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.

Error while calling Script Include from Client Script

rpoola
Tera Contributor

Hi,

I am getting following error while calling script include from client script. I don't have clue. Can anybody help me out.

Problem when trying to get a Rhino object: ConversionError: The undefined value has no properties. (sys_script_include.d22e7bdbc0a8016500a18e024bfc9aa3; line 4):

Client Script :

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

var cdt = g_form.getValue('u_start_date'); //Choose the field to add time from  

//alert(cdt);

if(cdt != ''){

var ajax = new GlideAjax('VBODateTimeUtils');  

ajax.addParam('sysparm_name', 'addVBODateTimeAmount');  

ajax.addParam('start_date', cdt);  

ajax.getXML(doSomething1);  

}

function doSomething1(response){  

var answer = response.responseXML.documentElement.getAttribute("answer");

alert(answer);  

}

   

}

Script Include :

var VBODateTimeUtils = Class.create();

VBODateTimeUtils.prototype = {

addVBODateTimeAmount: function(){  

//gs.info("Testing");

var start_date = this.getParameter('start_date');    

var start_date_GD = GlideDateTime(start_date);  

start_date_GD.addDays(7);

return start_date_GD;  

},

      type: 'VBODateTimeUtils'

};

6 REPLIES 6

Shishir Srivast
Mega Sage

Hi Ravi,



In your client script you have define a variable as start_date that is wrong, you have to keep the sysparm with all the variables, so your variable should be like sysparm_start_date and the get value form this variable in script include.



http://wiki.servicenow.com/index.php?title=GlideAjax#Using_GlideAjax : Any extra parameters may be passed in, all of which must begin with sysparm_.



it should be like ajax.addParam('sysparm_start_date', cdt); in your client script's 7th Line


it should be like var start_date = this.getParameter('sysparm_start_date'); in your script include's 5th Line


Dhruv Chandan
Giga Guru

Hi Poola,



Have highlighted the changes in bold.



The script should be as following:-



Client Script :



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


var cdt = g_form.getValue('u_start_date'); //Choose the field to add time from


//alert(cdt);


if(cdt != ''){


var ajax = new GlideAjax('VBODateTimeUtils');


ajax.addParam('sysparm_name', 'addVBODateTimeAmount');


ajax.addParam('sysparm_start_date', cdt);


ajax.getXML(doSomething1);



}


function doSomething1(response){


var answer = response.responseXML.documentElement.getAttribute("answer");


alert(answer);


}


 


}




Script Include :



var VBODateTimeUtils = Class.create();


VBODateTimeUtils.prototype = {


addVBODateTimeAmount: function(){


//gs.info("Testing");


var start_date = this.getParameter('sysparm_start_date');  


var start_date_GD = GlideDateTime(start_date);


start_date_GD.addDays(7);


return start_date_GD;


},




      type: 'VBODateTimeUtils'


};



Hoping this helps.



Regards,


Dhruv Chandan