- Home
- Forum
- Angular - EJ 2
- updating Id of a recurrence
updating Id of a recurrence
Hi, I am trying to update Id of a recurrence, after it is created. Usually, when a recurrence gets created on the scheduler, a random Id is automatically assigned. But, I want to assign my own Id to it, so that I can uniquely identify it using a primary key from the DB. The code below is what I am using. However, the Id of the recurrence remains the same.
public onActionBegin(args: ActionEventArgs): void {
//Store recurrence in the DB and get the primary key id from DB
this.someService.createRecurrence(this.someModel).then( (response)=>{
let data:Object=new DataManager(this.scheduleObj.getCurrentViewEvents()).executeLocal(new Query().where('RecurrenceID', 'equal', args.addedRecords[0]['Id'])); //Find recurrence which was just created
data[0].Id = response['id']; // Re-assign the ID obtained from the DB to the recurrence that just got created
this.scheduleObj.saveEvent(data[0], 'EditOccurrence'); //Save changes
console.log('before then:' + JSON.stringify(this.scheduleObj.getEvents())) //Id doesn't change even after updating
});
}
SIGN IN To post a reply.
6 Replies
VD
Vinitha Devi Murugan
Syncfusion Team
November 22, 2019 09:18 AM UTC
Hi Jose,
Syncfusion Greetings.
If we create the appointment through editor window, we generated the event Id in source end based on maximum id in the scheduler. If you want to maintain your own id you need to maintain the separate field in event object. Please refer below highlighted code and for the same we prepared the below sample.
public onActionBegin(args: ActionEventArgs): void {
if (args.data) {
args.data[0].PrimaryId = args.data[0].Id + 1; // add additional field and set your Id
}
}
In above sample we maintained PrimaryId field to store the additional information.
Kindly try the above solution and let us know, if you need further assistance on this.
Regards,
M.Vinitha devi
JL
jose lara
November 22, 2019 11:50 PM UTC
If you read my code completely, you will notice that I want to change the Id from within a promise (then method). The code sample you provided does not work within a promise. I would appreciate if you can read my question completely.
if (args.data) {
args.data[0].PrimaryId = args.data[0].Id + 1; // add additional field and set your Id
}
JL
jose lara
November 26, 2019 12:43 AM UTC
Any updates on this? Basically, I am looking to store the ID that I get from the DB to a newly created event, so that I can keep track of any user interactions with that event, such as updates or deletes to that event. The ID that the scheduler assigns, is not reliable or unique. When a calendar is shared by multiple users, the ID will not be unique. So, I am thinking of assigning the ID my DB is generating, before it gets rendered on the scheduler.
VM
Vengatesh Maniraj
Syncfusion Team
November 26, 2019 02:33 PM UTC
Hi Jose,
Sorry for the inconvenience
We have further reviewed your shared code snippet and found that you've filtered the events from getCurrentViewEvents and updated the event Id that's wrong because it doesn't reflect the change in UI and DB. Instead, we suggest using eventSettings.dataSource to filter the event and change it. Once changes are made, the refreshEvents method needs to be called to refresh the events. Please see the code shown below and we have prepared the sample below.
public onActionBegin(args: ActionEventArgs): void {
if (args.data && args.data[0]) {
const studentsObservable = this.scheduleService.getId();
studentsObservable.subscribe((scheduleData: any) => {
let data: Object = new DataManager(
this.scheduleObj.eventSettings.dataSource
).executeLocal(new Query().where("Id", "equal", args.data[0].Id));
data[0].Id = scheduleData.Id;
this.scheduleObj.refreshEvents();
});
}
}
Regards,
Vengatesh
JL
jose lara
November 29, 2019 12:46 AM UTC
Great! This is exactly what I wanted.
VD
Vinitha Devi Murugan
Syncfusion Team
November 29, 2019 05:10 AM UTC
Hi Jose,
Thanks for your update.
We are happy to hear that our solution has fulfilled your requirement.
Regards,
M.Vinitha devi
SIGN IN To post a reply.
- 6 Replies
- 3 Participants
-
JL jose lara
- Nov 22, 2019 04:10 AM UTC
- Nov 29, 2019 05:10 AM UTC