Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Client Script add days to date field

Community Alums
Not applicable

Hi,

I want to add dates to a date/time field in catalog item. Below is the code I am using but it is not working.

Client Script :-

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below

var daysToAdd;
if(g_form.getValue('u_itauditrequest_request_category') == "Expedited")
{
daysToAdd = 27*3600;
}
else if(g_form.getValue('u_itauditrequest_request_category') == "Standard")
{
daysToAdd = 45*3600;
}
else if(g_form.getValue('u_itauditrequest_request_category') == "Aggregated/Bulk")
{
daysToAdd = 90*3600;
}

var ga=new GlideAjax("VEN_addDaystoDate");
ga.addParam('sysparm_name', 'addDaystoDate');
ga.addParam("sysparm_daysToAdd","daysToAdd");
//ga.addParam("sysparm_startDate","startDate");
//alert(daysToAdd);

ga.getXML(duedate);

function duedate(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
g_form.setValue("due_date", answer);

}

 

Script Include :-

 

var VEN_addDaystoDate = Class.create();
VEN_addDaystoDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {

addDaystoDate:function(){

gs.include('DurationCalculator');
this.executeSample();
//var startDate=gs.nowDateTime();
executeSample:function()
{
var daysToAdd=this.getParameter('sysparm_daysToAdd');
gs.log("*** daysToAdd" +daysToAdd);

var dc = new DurationCalculator();

//this.addSchedule(dc);

var initialDate = new GlideDateTime(gs.nowDateTime());
dc.setStartDateTime(initialDate);

if(!dc.calcDuration(daysToAdd))
{
gs.log("*** Error calculating duration");
return;
}
return dc.getEndDateTime();
}
},

/*addSchedule:function(durationCalculator){

var scheduleName = "8-5 weekdays excluding US holidays";
var grSched = new GlideRecord('cmn_schedule');
grSched.addQuery('name', scheduleName);
grSched.query();
if(!grSched.next())
{
gs.log('*** Could not find schedule "'+ scheduleName +'"');
return;
}

durationCalculator.setSchedule(grSched.getUniqueValue(),"GMT");

},*/

type: 'VEN_addDaystoDate'
});

 

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

Change 

ga.addParam("sysparm_daysToAdd","daysToAdd");

 

to

 

ga.addParam("sysparm_daysToAdd",daysToAdd);

 

Thanks,
Ashutosh

View solution in original post

2 REPLIES 2

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

Change 

ga.addParam("sysparm_daysToAdd","daysToAdd");

 

to

 

ga.addParam("sysparm_daysToAdd",daysToAdd);

 

Thanks,
Ashutosh

Community Alums
Not applicable

It worked, thanks a lot !!! in identifying that.