- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2016 07:52 AM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2016 08:22 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2016 08:05 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2016 08:18 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2016 08:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2016 08:39 AM
Thanks! The conversion is what I was looking for.