- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2020 01:46 PM
Hi,
some one suggest me about this use case how to solve
I created a notification, just update it a bit as below
but that notification has to carry only modified variables details only with Old value , new value of variable when we change variable value in RITM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2020 01:08 AM
please update as below and try once
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
template.print("<b>Summary of items:\n</b>");
var notiBodyString = event.parm2;
var parsedData = JSON.parse(notiBodyString);
template.print('<br>');
gs.info("parsedData" + parsedData);
template.print('parsedData----------' + parsedData + '\n' + '\n');
var notiLength = parsedData.length;
template.print('<br>');
gs.info('notiLength' + notiLength);
template.print('notiLength----------' + notiLength);
for(var i=0;i<parsedData.length;i++){
template.print('Variable ' + parsedData[i].variableName + ' old value ' + parsedData[i].oldValue + ' new value ' + parsedData[i].currentValue);
}
})(current, template, email, email_action, event);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2020 04:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2020 05:00 AM
if your BR is on sc_req_item table then current object should work
Also current.fieldName.changes() works only in BR and not any other script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2020 05:30 AM
i have removed current.fieldName.changes() i tried still showing same error
template.print("<b>Summary of items:\n</b>");
var item = new GlideRecord("sc_req_item");
if (item.get(current.sys_id)) {
var cur = current.variables.getElements();
var pvr = previous.variables.getElements();
for (var i = 0; i < cur.length; i++) {
gs.info('EmailScript:'+cur+'--'+pvr);
if (cur[i] != pvr[i]) {
var question = cur[i].getQuestion().getLabel();
var cur1 = cur[i];
var prv1 = pvr[i];
gs.info('EmailScript1:'+cur1+'--'+prv1);
template.print(cur[i].getQuestion().getLabel() +" :" + question + "---" + "Current :" + cur1 + "--" + "Previous :" + prv1 + "<br/>");
}
}
}
result:
org.mozilla.javascript.EcmaError: Cannot read property "variables" from null
Caused by error in Email Script: 'sc_req_item_script_3' at line 6
3: var item = new GlideRecord("sc_req_item");
4: if (item.get(current.sys_id)) {
5: var cur = current.variables.getElements();
==> 6: var pvr = previous.variables.getElements();
7: for (var i = 0; i < cur.length; i++) {
8: gs.info('EmailScript:'+cur+'--'+pvr);
9: if (cur[i] != pvr[i]) {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2020 05:37 AM
Hi,
you should use this
var cur = item.variables.getElements();
But this line won't work as previous object is not available in email script
var pvr = previous.variables.getElements();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2020 05:39 AM
how can we get previous value of variable , any alternative option do we have?