Scheduler lightbox 'options' undefined

I have altered the lightbox that appears in the scheduler and I am using a select, as outlined here (docs.dhtmlx.com/scheduler/select.html). I am performing a jQuery ajax request to my database to get a list of options for the select dropdown; if I console.log in the callback for this ajax request, I can see that it is performed successfully and assigned to a variable.

However, options is sometimes undefined, which causes an error to be thrown in the rendering of the select in dhtmlxscheduler.js (line 5178). The error only seems to occur on some refreshings of the page - do you have any idea why this might be? Usually the page loads fine with no errors, but this inconsistent behaviour is worrying!

Hello,
it’s hard to tell without any kind of code sample. But since the error happens only occasionally, probably you’ve got the race state between loading of options and initialization of the scheduler.
for example, this may happen if send ajax when the page starts and save loaded options into some variable which is later used to initialize lightbox select which happens on document ready - in this case there is no guarantee that ajax will finish before document ready is fired, and by the time scheduler is initialized options may still be undefined.

You can load options after scheduler is initialized, in order to do so, you need following: