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

Chuck Tomasi
Tera Patron

Hi Robert,



The addQuery()/query() methods are used to search for records. They are typically followed by an if/while using the next() method to determine if records were found and get the details of them.



If all you are doing is creating a new record, then leave those out.



var newScheduleEntry = new GlideRecord('cmn_schedule_span');


newScheduleEntry.initialize();


newScheduleEntry.name = 'test 2';


newScheduleEntry.start_date_time = producer.var_checkout_date;


newScheduleEntry.end_date_time = producer.var_return_date;


newScheduleEntry.insert();


Community Alums
Not applicable

Sorry, I should have removed that. It was left from an earlier testing. This is what I have now:



var newScheduleEntry = new GlideRecord('cmn_schedule_span');


newScheduleEntry.initialize();


newScheduleEntry.schedule = 'Wifi Hotspot';


newScheduleEntry.name = 'test 2';


newScheduleEntry.start_date_time = producer.var_checkout_date;


newScheduleEntry.end_date_time = producer.var_return_date;


newScheduleEntry.insert();



I get the error message "The dates and times you entered were not valid" once the record is created


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.




Community Alums
Not applicable

Thanks! The conversion is what I was looking for.