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

@Manjunath M ,

 

I don't see formatting working in infoMessage, the script that I suggest do works in scripting but for infoMessage when it changesa to HTML somehow it is not able to process. If you see below script same code is able to butify in description field but not in info message :

 

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

    var z = JSON.stringify(x, null, 1);

    gs.addInfoMessage(z);
    current.description = z;

kamleshkjmar_0-1667818489441.png

 

kamleshkjmar_1-1667818537787.png

 

Thanks,

Kamlesh

 

@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

 

 

@Manjunath M ,

 

Just forgot to mention, however you can do one thing to beautify it. You can use parameters of stringify(), as shown below

 

 

	var x = {"abc":"sdfa", "test":"sadfafasf"}
	var z = JSON.stringify(x,null,1); // This bustifies the JSON in string format with extra space

 

But above butifies when you set this value in any field. Infomessage I doubt will be able to butify using parameter also.

 

I hope this help.

 

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

 

Regards,

Kamlesh

MD AQUIB KHAN
Giga Guru

Hi ,

You are already getting the information in the JSON Format as per the screenshot shared.  Please elaborate.

I tried to create in my PD. I guess this has already been achieved.

//

(function executeRule(current, previous /*null when async*/) {

// Add your code here
gs.addInfoMessage('enter BS');
var payload = {
"result": {
"short_description": current.getValue('short_description'),
"active": current.getValue('active')
}
};

//var json = JSON.stringify(payload);
var json = JSON.stingify(payload);
gs.addInfoMessage(json);
})(current, previous);

I have created on Before Insert and Update and when the state is WIP. Please find the screenshot.

MDAQUIBKHAN_0-1667818243639.png