Sending JSON.stringify() is sending Object Object

Community Alums
Not applicable

Hi Team,

 

On sending data from script include using JSON.stringify(arr),we are getting message as [{}] ,we are only sending single value for a scenario. 

 

But when we print the value before JSON.stringify , we do get the proper message in gs.info() as "Carrier" .This value is not getting sent using stringify

2 ACCEPTED SOLUTIONS

Samaksh Wani
Giga Sage
Giga Sage

Hello @Community Alums 

 

use :-

JSON.stringify(arr.toString());

 

Plz Mark my Solution as Accept, if you find it Helpful.

 

Regards,

Samaksh

 

 

 

 

View solution in original post

 

var fixedByChoice = JSON.parse(answer);
var nameArr = fixedByChoice.split(',');  // add these line after above one.

for(var i=0; i<namesArr.length;i++){ // replace your for loop with mine
// ur code
}

 

 

Plz Mark my Solution as Accept, if you find it Helpful.

 

Regards,

Samaksh

View solution in original post

8 REPLIES 8

Ahmmed Ali
Mega Sage

Hello @Community Alums 

 

It would be helpful if you can post the script you are using.

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Samaksh Wani
Giga Sage
Giga Sage

Hello @Community Alums 

 

use :-

JSON.stringify(arr.toString());

 

Plz Mark my Solution as Accept, if you find it Helpful.

 

Regards,

Samaksh

 

 

 

 

Community Alums
Not applicable

@Samaksh Wani .Now its showing the proper message in alert(answer) as "Carrier" but when we do addOption. We get as below:

 

Ankur20_0-1689599841778.png

 

 

Please see my script as below:

if(newValue == 'TPx'){
var caseType = g_form.getValue('u_new_case_type');
var ga = new GlideAjax('CarrierCaseFixedByOptions');
ga.addParam('sysparm_name', 'fixedbyChoices');
ga.addParam('sysparm_owner', newValue);
ga.addParam('sysparm_casetype', caseType);
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var fixedbyChoice = JSON.parse(answer);
//g_form.addOption('u_fixed_by', fixedbyChoice.fixedbyValue, fixedbyChoice.fixedbyLabel);
g_form.clearOptions('u_fixed_by');
g_form.addOption('u_fixed_by', '', '--None--');
for (var i = 0; i < fixedbyChoice.length; i++) {
//g_form.addOption('u_fixed_by', answer[i], answer[i]);
g_form.addOption('u_fixed_by', fixedbyChoice[i].toString(), fixedbyChoice[i].toString());
}
});

can you post Script Include script as well here?

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali