- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2019 01:41 PM
Hi,
I have a requirement for setting a field value as 5 business days minus the set date on the another field on a catalog form.
For example-
If the Delivery_Date is set as 11-15-2019, the Actual_Start_date should be 11-08-2019, taking into account the 8-5 weekday schedule.
Looking for on how to configure the Actual_Start_date.
The delivery date can be modified by the user submitting the request, so I know it should be a catalog client script, but I am quite new to coding and after thoroughly searching the community, could not find the answer I needed.
So requesting the ServiceNow Community for assistance.
Thanks.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2019 08:49 AM
Hi All,
I finally made is possible by following a minimal scripting method using the Timer.
As suggested by TJW in set a timer in workflow based on a variable, I was able to set the schedule and make the timer wait as per my needs.
Thank you all for your support 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2019 09:45 AM
Can you please share the correct code? I might not be able to get the correct place where you wanted the change.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2019 09:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2019 09:52 AM
Did the same changes, nothing.
Is the OnChange script correct? I mean I tried to change the date on the form and still the Actual Date did not populated.
Should I try the OnLoad or is it something else which is messing this up?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2019 09:54 AM
Can you share your current scripts ?. Also try adding alert of answer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2019 10:08 AM
Sure,
So I have 2 fields, Delivery_date and Actual_start_date.
I have the default value set to add 10 business days to Delivery_date from the date of opening the catalog form using-
javascript:var gdt = new GlideDateTime();
var dc = new DurationCalculator();
dc.setSchedule('db58361cdbf317003e8a0f4dca96196e'); // Schedule sys_id
dc.setStartDateTime(gdt);
dc.calcDuration(10*10*3600); // 8-6 Schedule so 10 Hrs
var edt= new GlideDateTime(dc.getEndDateTime())
edt.getDate();
Then as Ajay suggested, I am using the Catalog Client Script and Script Include to populate the Actual_start_date field.
Catalog Client Script-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var deliverydate= g_form.getValue('delivery_date');//variable field
var ajax = new GlideAjax('AjaxDurCalc');
ajax.addParam('sysparm_name','durCalc');
ajax.addParam('sysparm_deliv',deliverydate);
ajax.getXMLWait();
var answer = ajax.getAnswer();
g_form.setValue('actual_start_date', answer);
}
And the Script Include-
var AjaxDurCalc = Class.create();
AjaxDurCalc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
days:function(){
var deliver=this.gertParameter('sysparm_deliv');
var ps = new GlideDateTime(deliver);
ps.addDays(-5);
var datebefore =ps.getDate();
return datebefore;
},
type: 'AjaxDurCalc'
});