Page 1 of 1

Async call in beforeEventSave not working

Posted: Wed May 17, 2023 3:53 pm
by smalchow

We need to call an asynchronous function on the event 'beforeEventSave'. Depending on the functions response, the event changes should be applied or rejected. According to the documentation we need to set context.async to true and call context.finalize(false) to reject the event the event save.
Here is the code simply using setTimeout()

 async beforeEventSave({ eventRecord, source: context }) {
                    context.async = true;
                    setTimeout(() => {
                        context.finalize(false);
                    }, 5000);
                    return false;
                },

The console returns: "Uncaught TypeError: context.finalize is not a function"
Can you tell me where the error is?

Best regards


Re: Async call in beforeEventSave not working

Posted: Wed May 17, 2023 5:23 pm
by Animal

It's a Javascript authoring error. You are using the event firer, the source as the context.

https://bryntum.com/products/calendar/docs/api/Scheduler/feature/EventEdit#event-beforeEventSave


Re: Async call in beforeEventSave not working

Posted: Fri May 26, 2023 11:26 am
by smalchow

Oh sorry, I found that example in another Forum entry and thought this was the way of going.. Directly accessing the context works fine, thank you!


Re: Async call in beforeEventSave not working

Posted: Fri May 26, 2023 11:29 am
by Animal

Never copy/paste example code.

Read and understand it, then use the principles in your own design.