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.

Incorrect value passing form script include to client script

Rameshnathan
Tera Expert

Hi

i want to pass this tow value from script include to client script,

its displaying correct value in the script include but then i get this thought client script its displaying this error     ([object XMLHttpRequest])

Script Include   :-

if(grp.next()){

asgment.push(grp.getDisplayValue('assignment_group'));

priority.push(grp.getDisplayValue('priority'));

}

var result =[asgment,priority];

return result;

Client Script :-

function CallBack(response){

alert(response);

g_form.setValue('short_description', response);

}

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Ramesh,



When you return a payload from the server, it must be a string. I HIGHLY recommend using JSON to ensure arrays, or objects, are preserved properly and that commas or other special characters don't get in the way of a split command. Here's an example of how you can return the priority and assignment_group display value as a JSON object, stringify it on the server side and parse it on the client side, then create your short_description based on those two properties. Sorry for the crappy formatting in the community editor.



if(grp.next()){



var myAnswer = {


        "assignment_group" : grp.getDisplayValue('assignment_group'),


"priority" : grp.getDisplayValue('priority')


};



}




var result = JSON.stringify(myAnswer);



return result;




Client Script :-



function CallBack(response){


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


var myObj = JSON.parse(answer);


var myString = myObj.assignment_group + ' ' + myObj.priority;



g_form.setValue('short_description', myString);



}


View solution in original post

16 REPLIES 16

Simon Christens
Kilo Sage

Try


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


Now its showing this



find_real_file.png


Hi



Yes becuse you are returning an Array
As you only have 2 values that you are getting (because ur using if(grp.next) then i might be overkill to parse 2 arrays in a new array (result) and then returning an array containing more arays.



var result = [];


if(grp.next()){


result.push(grp.getDisplayValue('assignment_group');


result.push(grp.getDisplayValue('priority'));



}


return result.toString();



Now in your client script you will get a string containing assignment_grop,priority


That you can split and get index[0] and index[1]



var res = answer.split(',');



for(var i = 0; i < res.length; i++){



alert(res[i]);


}


Hi



i have tired this below code but no result is display




function CallBack(response){


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


var res = answer.split(',');


g_form.setValue('short_description', res[0]);


alert(res[0]);


alert(res[1]);


}