How do I retrieve all the appointments in a recurring event?

Hi, when a recurring event is saved, (for example from 9:00 to 17:00 from monday till friday), it gets saved as a single document in the MongoDB.
See below the examples:

schedule


Is there a possibility that i can get all the appointments on the days seperately with their StartTimes and EndTimes? I need to know all the days that has an appointment in it. 
So in this case for 19 oct:  
 "StartTime": {
        "$date": "2020-10-19T09:00:00.000Z"
    },
    "EndTime": {
        "$date": "2020-10-19T17:00:00.000Z"
    }

for 20 oct: 
 "StartTime": {
        "$date": "2020-10-20T09:00:00.000Z"
    },
    "EndTime": {
        "$date": "2020-10-20T17:00:00.000Z"
    }
21 oct:
 "StartTime": {
        "$date": "2020-10-21T09:00:00.000Z"
    },
    "EndTime": {
        "$date": "2020-10-21T17:00:00.000Z"
    }


etc..
I hope i made it understandable.
Thanks in advance


5 Replies 1 reply marked as answer

VD Vinitha Devi Murugan Syncfusion Team October 26, 2020 09:06 AM UTC

Hi Youssef, 
 
Greetings from Syncfusion Support. 
 
We have validated your reported query “Possibilities to get all the appointments of recurrence event” at our end. We have achieved your requirement by making use of getOccurrencesById public method of our scheduler and same can be available in following sample. 
 
 
 
Kindly try the above sample and get back to us if you need any further assistance. 
 
Regards, 
Vinitha 


Marked as answer

YL Youssef Lakdime October 27, 2020 06:59 PM UTC

Hi sycfusion support,

Thank you for your reply. I tried your solution, but I get this error message: `error TS2339: Property 'Id' does not exist on type 'Object'.`

this is my code:

console.log(this.scheduleObj.getOccurrencesByID(this.scheduleObj.eventsData[0].Id));

Also how can I retrieve the occurences from another component?
For example in my invoice.component.ts i have following code:
getAppointments(){

this.invoiceService.getAppointments().subscribe((data : any) => {
this.appointments= data.appointment;

});
};


in my server/invoice router:

router.get("/getAppointments", authRequired, (req, res) => {

User.findOne({_id: req.decoded.userId}).select('username email').exec((err, user) =>{
if(err){
res.json({success: false, message: err});
} if(!user){
res.json({success: false, message: 'User not found'});
} else {
user = user;
var query = {CreatedBy: user.username};
connection.db.collection('ScheduleData').find(query).toArray((err, cus) => {
res.json({appointment: cus});
console.log(req.body.params);


});
}
});

});

This gives me a JSON object (an array) of all the appointments. So how do i apply the GetOccurencesById() to all the appointments which has RecurrenceRule != null?

So like this:
this.appointments.forEach(detail => {


if(detail.RecurrenceRule != null) {
     console.log(detail.getOccurrencesByID(detail.id));
       }
} 

but this isnt working, i get: TypeError: detail.getOccurrencesByID is not a function


NR Nevitha Ravi Syncfusion Team October 28, 2020 07:48 AM UTC

Hi Youssef, 

Thanks for your update.  

As eventData is object type, you can access the Id field by casting it to any, please find the modified sample. 

public onBtnClick(): void { 
    console.log( 
      this.scheduleObj.getOccurrencesByID( 
        (this.scheduleObj.eventsData[0] as any).Id 
      ) 
    ); 
  } 

Q How can I retrieve the occurrences form another component 
 
We have checked your shared code and let you know that you have missed to access the getOccurrencesByID from schedule instance instead access it from appointment object which is the cause for the reported error. Please refer the above sample and get back to us if you need any further assistance. 

Regards, 
Nevitha 



YL Youssef Lakdime October 28, 2020 05:06 PM UTC

Hi, thanks for your assistance. However, i cant figure out why i am getting an empty array.

I want to do .getOccurencesById() on an array consisting of appointments ( which I recieve from a remote mongoDB). In the following code i try to do that:

this.service.getAppointments().subscribe((data : any) => {
this.appointments = data.appointment;

console.log(this.appointments); //gives me an array of 16 appointments

console.log( this.scheduleObj.getOccurrencesByID((this.appointments[0] as any).Id)); //empty array, here I want the occurences of the reoccuring event


});

However, I only get an empty array. What am i overlooking here?
If you need more code, please let me know.
Thanks in advance


VD Vinitha Devi Murugan Syncfusion Team November 4, 2020 06:46 AM UTC

Hi Youssef, 
 
Thanks for your update. 
 
We have validated your reported "getOccurrenceById returning empty array" problem at our end and suspect that you are trying to access the occurrences before rendering the scheduler, which is the cause for the empty array return. To resolve the reported problem , please use the codes below. 
 
var occurrences = this.scheduleObj.eventBase.generateOccurrence( this.data[0]); 
  console.log(occurrences); 
 
 
Kindly try the above sample and get back to us if you need any further assistance.  
 
Regards, 
Vinitha 


Loader.
Up arrow icon