Passing JSON object to email script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 01:20 AM
Hi,
My requirement is to send Email notification to Service owner whenever there is any change/update in CI fields.
The notification should contain "Name of Field", "Previous Value" and "New Value"
In order to achieve that I am using JSON to pass those field/values from BR to email_script as below:
Business Rule (on cmdb_ci and running after update):
var recipients = current.owned_by.toString();
var gru = GlideScriptRecordUtil.get(current);
var fields = gru.getChangedFieldNames(); //Get changed fields with database names
gs.include('j2js');
fields = j2js(fields);
var jsonObj = [];
var ciData;
for(var i in fields){
var field = fields[i];
ciData = {
"FieldLabel":current[field].getLabel(),
"FieldValue":current[field].getDisplayValue(),
"FieldPrevValue":previous[field].getDisplayValue()
};
jsonObj.push(ciData);
}
var jsonStr = JSON.stringify(jsonObj);
new AZNotificationI18NUtils().eventQueue('az.cmdb.updateCI', current, jsonStr, recipients);
}
//Here I am getting the output of jsonStr as below:
[{"FieldLabel":"Domain Name","FieldValue":"test2","FieldPrevValue":"test"},{"FieldLabel":"Provider tag","FieldValue":"BNL ServerList","FieldPrevValue":"Allianz Benelux"}]
Email script as below:
------------------------
var myList = JSON.parse(event.parm1);
for (var i = 0; i < myList.length; i++) {
gs.log("Result"+myList[i].FieldLabel);
}
--------------------------------
But I am getting error on line "var myList = JSON.parse(event.parm1);" as
"org.mozilla.javascript.EcmaError: Expected end of stream at char 131"
Could you please check if I am missing here something
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 02:53 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 03:04 AM
are you wring mail_script in notification itself or writing script in"Notification email scripts" and calling in notification?
also please have a log statement before json.parse to see what value is coming in event.parm1.
Thanks,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 03:21 AM
I am writing in notification email script and using that in my Notification.
I am receiving the value in parm1 as below
One strange thing, the order is not correct when I am receiving via event.parm1 in email script.
while as on sending from business rule , the format and order seems correct as in the above log starting with "kt5hlbg all ciDataValues"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 03:07 AM
Hi
It seems you are doing the wrong formatting of JSON. Try formatting properly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 03:35 AM
Hi Omkar,
Can you be more specific about the wrong formatting of JSON