How to add 10 days to current date using client scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 04:34 AM
I have a field "RequestedDate" in a service catalog form. Need to populate it with value equal to current date plus 10 days.
Please suggest implementing this with a client script.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 04:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 04:45 AM
Call a script Include and pass the value as parameter to make your calculations server side. Finally get the response object from the script Include and set accordingly.
var strtdt = gs.nowDateTime() ;
mytime = new GlideDateTime(strtdt);
var gtime1 = new GlideTime();
gtime1.setValue("10:00:00");
mytime.add(gtime1);
You can also refer below post:
https://www.servicenowguru.com/scripting/client-scripts-scripting/client-side-dates-in-servicenow/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 09:19 PM
I need a client script in onLoad()
gs. scripts not valid in client script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 09:33 PM
Can you try sometime like below.
Client callable Script Include:
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
calDate: function () {
var sdt = new GlideDateTime(this.getParameter('sysparm_date'));
sdt.addDaysLocalTime(10);
return sdt.getDate();
},
type: 'MyDateTimeAjax'
});
Client Script:
var gr = new GlideAjax('MyDateTimeAjax');
gr.addParam('sysparm_name', 'calDate');
gr.addParam('sysparm_date', g_form.getValue('u_date')); //Please update the field name
gr.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue('field_name', answer);
}