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

Hi Ankur,

i tried on RITM0010193 , but sure why it is not working this time

 

find_real_file.png

find_real_file.png

 

 

@Sironi 

It worked fine when I checked RITM0010193

Don't check in preview notification

You actually update those 3 variables on RITM and then save

Then check in email logs

find_real_file.png

Regards
Ankur

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

@Sironi 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

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

@Sironi 

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

 

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

Hi Yash,

i tried your script from Email script.

template.print("<b>Summary of  items:\n</b>");
//var question, i, prv1, cur1;
var item = new GlideRecord("sc_req_item");
if (item.get(current.sys_id)) {
if (current.variables.changes()) {
    var cur = current.variables.getElements();
    var pvr = previous.variables.getElements();
    for (var i = 0; i < cur.length; i++) {
        if (cur[i] != pvr[i]) {
            var question = cur[i].getQuestion().getLabel();
            var cur1 = cur[i];
            var prv1 = pvr[i];
            template.print(cur[i].getQuestion().getLabel() +" :" + question + "---" + "Current :" + cur1 + "--" + "Previous :" + prv1 + "<br/>");
        }
    }
}
}

 

 

i just updated Value variable , but Result is not coming properly, could you please help me 

Result :