Required alert in JSON Format

Manjunath M
Tera Contributor

I want to display AddInfoMessage in JSON format is it possible?I am getting alert in string format.

1 ACCEPTED SOLUTION

@Manjunath M ,

 

I just did a trick and it worked. As whatever you right in the addInfoMessage it changes to HTML. So I just played a trick with the parameter of stringify() and it worked. Try the below script:

 

 

 

var x = {
        "abc": "sdfa",
        "test": "sadfafasf"
    };

    var z = JSON.stringify(x, null, "<br/>");  // Use break line in the last parameter

    gs.addInfoMessage(z);

 

 

 

Just make sure you don't use it for setting value of any field as it will appear as it is.

kamleshkjmar_2-1667818806281.png

 

I hope this help.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

 

 

View solution in original post

8 REPLIES 8

Sails
Kilo Sage

Hi, Can you provide the sample you were using for this?

It may be clueless to guide based on the question asked.

Sails
ServiceNow Consultant
United Kingdom

I wrote Business rule for Incident,In When to run section ,I given after for when field

Hi @Manjunath M ,

 

JSON is the format to use for exchanging info and consuming it. If you are to print the data then, you are doing it right by stringifying it.  JSON is an Object and Objects are not printed, it will print in the format [object object].

 

I hope this help.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

 

Is It possible to print like this:

"short_description" : "Email Server is down 1"

"active" : "1"

(in serparate line)