How to send notification with Old value , new value of variable when we change variable value in RITM

Sironi
Kilo Sage

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

 

 

1 ACCEPTED SOLUTION

@Sironi 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

41 REPLIES 41

i tried from Emailscript, but it is giving warning like below

find_real_file.png

@Sironi 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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]) {

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

how can we get previous value of variable , any alternative option do we have?