JSON.parse validation

Deepthi13
Tera Expert

Hi team, i am trying JSON.stringify() and JSON.parse() through email script and business rule, it is not working as expected please suggest

Business Rule:

var obj = {"preName":previous.it_application_owner.name, "curName":current.it_application_owner.name, "updatedOn":current.sys_updated_on};
var str = JSON.stringify(obj);
gs.eventQueue("sn_apm.ApplicationOwnerChanges",current,"test",str);
gs.info("@@@ business rule "+str);

 

Email Script:

var result = JSON.parse(event.str);
gs.info("@@@ email script " + result.preName + " was " + result.curName + " " + result.updatedOn);
template.print("\n" + "Application Owner: " + event.parm1 + " was " + event.parm2);

2 ACCEPTED SOLUTIONS

Jerick I
Kilo Sage
Kilo Sage

Hi @Deepthi13,

 

Can you tell me whether your business rule runs before or after? Can you try the below code also.

 

var obj = {"preName":previous.it_application_owner.name+"", "curName":current.it_application_owner.name+"", "updatedOn":current.sys_updated_on+""};
var str = JSON.stringify(obj);
gs.eventQueue("sn_apm.ApplicationOwnerChanges",current,"test",str);
gs.info("@@@ business rule "+str);

Please mark as Correct / Helpful if this solves your issue.
Regards,
Jeff

View solution in original post

SanjivMeher
Kilo Patron
Kilo Patron

So looks like you are passing the str value as event parameter 2

gs.eventQueue("sn_apm.ApplicationOwnerChanges",current,"test",str);

 

So you should use parm2 in the email script

var result = JSON.parse(event.parm2);
gs.info("@@@ email script " + result.preName + " was " + result.curName + " " + result.updatedOn);
template.print("\n" + "Application Owner: " + event.parm1 + " was " + event.parm2);


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

2 REPLIES 2

Jerick I
Kilo Sage
Kilo Sage

Hi @Deepthi13,

 

Can you tell me whether your business rule runs before or after? Can you try the below code also.

 

var obj = {"preName":previous.it_application_owner.name+"", "curName":current.it_application_owner.name+"", "updatedOn":current.sys_updated_on+""};
var str = JSON.stringify(obj);
gs.eventQueue("sn_apm.ApplicationOwnerChanges",current,"test",str);
gs.info("@@@ business rule "+str);

Please mark as Correct / Helpful if this solves your issue.
Regards,
Jeff

SanjivMeher
Kilo Patron
Kilo Patron

So looks like you are passing the str value as event parameter 2

gs.eventQueue("sn_apm.ApplicationOwnerChanges",current,"test",str);

 

So you should use parm2 in the email script

var result = JSON.parse(event.parm2);
gs.info("@@@ email script " + result.preName + " was " + result.curName + " " + result.updatedOn);
template.print("\n" + "Application Owner: " + event.parm1 + " was " + event.parm2);


Please mark this response as correct or helpful if it assisted you with your question.