How to get the previous value of fields and put it on cc.

Dizy M
Tera Expert

Hi!

 

I'm having a problem with getting the previous value of my 3 fields and put them on cc in 1 email.

 

We have 3 fields:

field name: supervisor_eid

field name: assignee_eid

field name: hr_eid

 

Everytime the user update these 3 fields simultaneously or update 2 fields simultaneously  or just update only 1 field , there will be an email notification that will be sent to the New supervisor, New Assignee, and New HR . The previous supervisor , assignee and HR should be "CC" in the email.

 

 

Is there any way on how to add the previous assignee and previous hr on the cc using BR ? coz we cant get the previous values using email script only..  

 

 

Business Rule:

DizyM_0-1699435373398.png

 

 

Email Script:

DizyM_1-1699435584511.png

 

Thank you in advance!

 

1 ACCEPTED SOLUTION

Anand Kumar P
Giga Patron
Giga Patron

Hi @Dizy M ,
You can achieve by pushing to array access from email script to set in CC update script as per your requirement.

var supervisorValues = [];
var assigneeHrValues = [];

if (current.supervisor_eid != previous.supervisor_eid) {
    supervisorValues.push(current.supervisor_eid); 
    supervisorValues.push(previous.supervisor_eid);
}

if (current.assignee_eid != previous.assignee_eid) {
    assigneeHrValues.push(previous.assignee_eid); 
}

if (current.hr_eid != previous.hr_eid) {
    assigneeHrValues.push(previous.hr_eid); // Add previous HR
}

gs.eventQueue('email_cc_event', current, supervisorValues, assigneeHrValues);
Access in email script:
var emailList = [];
emailList = event.parm1;
if (!emailList.nil()) {
   var emailAddr = emailList.split(",");
for (var i = 0; i < emailAddr.length; i++) {
      email.addAddress("cc", emailAddr[i], "");
}
Do same for parm2

Please mark it as solution proposed and helpful if its serves your purpose.

Thanks,

Anand

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Dizy M 

you can send all 3 previous and current values in JSON and then send it in parm1 or parm2

then in email script parse it and show the value of both previous and current

I shared solution for something similar for this earlier. just enhance it

Show previous assignmnet group, state values from fields into notification 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Anand Kumar P
Giga Patron
Giga Patron

Hi @Dizy M ,
You can achieve by pushing to array access from email script to set in CC update script as per your requirement.

var supervisorValues = [];
var assigneeHrValues = [];

if (current.supervisor_eid != previous.supervisor_eid) {
    supervisorValues.push(current.supervisor_eid); 
    supervisorValues.push(previous.supervisor_eid);
}

if (current.assignee_eid != previous.assignee_eid) {
    assigneeHrValues.push(previous.assignee_eid); 
}

if (current.hr_eid != previous.hr_eid) {
    assigneeHrValues.push(previous.hr_eid); // Add previous HR
}

gs.eventQueue('email_cc_event', current, supervisorValues, assigneeHrValues);
Access in email script:
var emailList = [];
emailList = event.parm1;
if (!emailList.nil()) {
   var emailAddr = emailList.split(",");
for (var i = 0; i < emailAddr.length; i++) {
      email.addAddress("cc", emailAddr[i], "");
}
Do same for parm2

Please mark it as solution proposed and helpful if its serves your purpose.

Thanks,

Anand