pass entire gliderecord back to client script

rajeeshraj
Tera Guru

How can i pass the entire gliderecord from script include to client script. I am querying location table based on a location name, i would like to get the entire record for the particular location from the scriptinclude back to the client script. Is there an example code?

19 REPLIES 19

I don't have one. I am new to ServiceNow and would like to know how JSON can be used to return entire table record from Script Include to client script.


Hi Rajeesh,



You can pass entire glideRecord from script include to client script, by using following script include code:



var glideRecord = new GlideRecord('incident');


          glideRecord.get('sys_id'); //pass the sys_id of the incident you want to pass



var xmlSerializer = new GlideRecordXMLSerializer();


var taskXML = xmlSerializer.serialize(glideRecord);


var helper = new XMLHelper(taskXML);


var xmlObj = helper.toObject();


var json = new global.JSON().encode(xmlObj);


This is my client script and script include, please let me know how i can pass entire record from script include to client script



Client Script onChange




*************************************************************************




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


    if (isLoading) {


          return;


    }


if(newValue == '')


{


g_form.setValue('locName_ref',"");


return;


}


    //Type appropriate comment here, and begin script below


var ga = new GlideAjax('test_request');


ga.addParam('sysparm_name','popLocDetails');


ga.addParam('sysparm_loc',newValue);


ga.getXML(getFields);



}






function getFields(response) {


var result = response.responseXML.getElementsByTagName("result");



var u_locname = result[0].getAttribute("user_location");




g_form.setValue('locName_sl',u_locname);


}


******************************************************************************************************



Script Include






var test_request = Class.create();


test_request.prototype = Object.extendsObject(AbstractAjaxProcessor, {



popLocDetails : function()


{


var result = this.newItem("result");


var locat = this.getParameter('sysparm_loc');



var gr = new GlideRecord('cmn_location');


gr.addQuery('sys_id',locat);


gr.query();


if(gr.next())


{


result.setAttribute("user_location",gr.u_name);


}


},



type: 'test_request'


});




****Here i am only returning the location name, how can i return the entire record back to client script


On which table your running your onChange client script and which table glideRecord you want to pass?


I ma running onchange on Service catalog variable and querying location table