- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2017 06:28 AM
I can't seem to figure out how to add a schedule to a script that calculates a custom targeted due date field based on a requested_date variable. I would like the script to take todays date and add 3 days excluding weekends. Does anyone have this script already?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 12:30 PM
Hi Danielle,
Strange, I created a test Catalog Item with a Date/Time variable and used the script, but changed line 22 to just:
dueDateGdt;
It seemed to work for me to set the date for 3 days.
Screenshot of Date/Time variable:
Screenshot of Default Value of Date/Time variable:
Default Value code:
javascript: var nowGdt = new GlideDateTime(); var nowGdt = new GlideDateTime(); var myScheduleName = '8-5 weekdays'; var dueDays = 3; var dueWorkingHours = 8; var dueSeconds = dueDays*dueWorkingHours*60*60; var leadTime = new GlideDuration(dueSeconds*1000); var dueDateGdt; var schedRec = new GlideRecord('cmn_schedule'); if (schedRec.get('name', myScheduleName)) {var sched = new GlideSchedule(schedRec.sys_id); dueDateGdt = sched.add(nowGdt, leadTime, '');} dueDateGdt;
Thanks,
John
P.S. Normally, we would create a custom Script Include with a helper function: getDueDate('schedule_name', 'number_of_days') and then use that for the variable default value: javascript:new myCatalogVariableHelper().getDueDate('8-5 Weekday', 3);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2017 05:02 PM
Hi Keith,
Great, thank you for your comment. It is always nice to know when a posting helped others.
Cheers,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2017 08:59 AM
Or the Istanbul equivalent... https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/script/server-scripting/concept...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 12:30 PM
Hi Danielle,
Strange, I created a test Catalog Item with a Date/Time variable and used the script, but changed line 22 to just:
dueDateGdt;
It seemed to work for me to set the date for 3 days.
Screenshot of Date/Time variable:
Screenshot of Default Value of Date/Time variable:
Default Value code:
javascript: var nowGdt = new GlideDateTime(); var nowGdt = new GlideDateTime(); var myScheduleName = '8-5 weekdays'; var dueDays = 3; var dueWorkingHours = 8; var dueSeconds = dueDays*dueWorkingHours*60*60; var leadTime = new GlideDuration(dueSeconds*1000); var dueDateGdt; var schedRec = new GlideRecord('cmn_schedule'); if (schedRec.get('name', myScheduleName)) {var sched = new GlideSchedule(schedRec.sys_id); dueDateGdt = sched.add(nowGdt, leadTime, '');} dueDateGdt;
Thanks,
John
P.S. Normally, we would create a custom Script Include with a helper function: getDueDate('schedule_name', 'number_of_days') and then use that for the variable default value: javascript:new myCatalogVariableHelper().getDueDate('8-5 Weekday', 3);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2018 12:33 PM
I have taken this and created a script include. The issue i am having is my system is set for a 12hr clock but my result is being return in a 24hr clock so on my catalog item i get an invalid text data for the date. Here is my script include and my client script.
Script include:
var SetDueDate = Class.create();
SetDueDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
SetDueDate : function() {
var dueDays = this.getParameter('sysparm_dueDays');
var nowGdt = new GlideDateTime();
var myScheduleName = '8-5 weekdays';
var dueWorkingHours = 8;
var dueSeconds = dueDays*dueWorkingHours*60*60;
var leadTime = new GlideDuration(dueSeconds*1000);
var schedRec = new GlideRecord('cmn_schedule');
if (schedRec.get('name', myScheduleName))
{
var sched = new GlideSchedule(schedRec.sys_id);
return sched.add(nowGdt, leadTime, '');
}
},
type: 'SetDueDate'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var urgency = g_form.getValue('urgency');
var dueDays;
if (urgency == '0'){
dueDays = 14;
}
else if (urgency == '1'){
dueDays = 28;
}
else if (urgency == '2'){
dueDays = 42;
}
else if (urgency == '3'){
dueDays = 60;
}
g_form.setValue('due_date',setDueDate(dueDays));
function setDueDate(dueDays){
var ga = new GlideAjax('SetDueDate');{
ga.addParam('sysparm_name', 'SetDueDate');
ga.addParam('sysparm_dueDays', dueDays);
ga.getXMLWait();
return ga.getAnswer();
}
}
}
Any help on the 24hr clock to 12hr clock conversion would be great!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2018 02:19 PM
Hi Holly,
Unfortunately, I am not sure how to get the return value from the
sched.add(nowGdt, leadTime, '')
method to accommodate a 12 Hour clock.
Documentation for Method for reference: GlideSchedule
Seems like we would need to convert a GlideDateTime object to 12 Hour format...
Sorry,
John G