Script help: Json printing only [object object]

Rupal Mehta
Kilo Contributor

Trying below script but the JSON only prints [object object]. What is the mistake here.

if (gr.isValidRecord()) {

result.u_class = gr.u_env_class;

result.u_status = gr.install_status;

}

return JSON.stringify(result);
1 ACCEPTED SOLUTION

Shubham Tipnis
Kilo Sage
Kilo Sage

Hi Rupal,

 

gr.field_name returns the object. It's better to convert it to string while saving it in JSON.

 

if (gr.isValidRecord()) {

 

result.u_class = gr.u_env_class.toString();

 

result.u_status = gr.install_status.toString();

 

}

 

return JSON.stringify(result);

 

Please mark correct/helpful if applicable.

 

Regards,

Shubham

Regards,
Shubham Tipnis
 ServiceNow Enthusiast
️ 3x Rising Star (2022–2024) – ServiceNow Community
 Sharing insights, use cases & real-world learnings from the Now Platform
 Always learning. Always building.

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

can you share your complete script?

You are already using JSON.stringify() so it should return a json string

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader