How do I initialize a new Schedule Entry in an existing schedule?

Community Alums
Not applicable

I am trying to add a schedule entry on submission of a record producer that will contain a start date/time and end date/time. This is what i have just to create a base schedule

var newScheduleEntry = new GlideRecord('cmn_schedule_span');

newScheduleEntry.addQuery('schedule', 'Wifi Hotspot');

newScheduleEntry.query();

newScheduleEntry.initialize();

newScheduleEntry.name = 'test 2';

newScheduleEntry.start_date_time = producer.var_checkout_date;

newScheduleEntry.end_date_time = producer.var_return_date;

newScheduleEntry.insert();

Can I get any assistance as to why this isn't working? I believe it has something to do with how the date/time field is formatted but I'm not sure.

1 ACCEPTED SOLUTION

The reason is because the schedule's start/end times are a different data type than the producer's. You need to convert the glide date time to a schedule date time. See this example (code on the right) for a way to do that.




View solution in original post

5 REPLIES 5

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Robert,



To add, you can refer sample ex in the below wiki.


Refer section 12.1 in case the req is to create a new record.


Refer section 8.9 in case the req is to query the existing record.


https://wiki.servicenow.com/index.php?title=GlideRecord#initialize