The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Notification to a group when field changes in particular table

Priyanka Chaud1
Tera Contributor

Hi Servicenow Experts,

I have a requirement for my cmdb table...When 4 fields on the form has been changed they want to send notification to a group with the old and new value of that field that has been changed on the record.

For this i created a event, there BR after update on cmdb table here is the BR script...not sure what to put in eventqueue syntax is correct? Also after this need to create email script so need help on that as i am not getting what to code in email script to get that data to create notification. Can someone please help me on this req it would be great help. Thanks @Ankur Bawiskar @sohail_mohamad @HrishabhKumar @Sandeep Rajput @Anil Lande 

Attaching br so far what i have done:-

var arr=[];
    if(current.name.changes()){
      var temp1={};
     temp1['field']='name';
    temp1['oldvalue']= previous.name;
    temp1['newvalue']= current.name;
    arr.push(temp1);
    }
    if(current.install_status.changes()){
      var temp2={};
     temp2['field']='install_status';
    temp2['oldvalue']= previous.install_status;
    temp2['newvalue']= current.install_status;
    arr.push(temp2);
    }

    if(current.support_group.changes()){
      var temp3={};
     temp3['field']='support_group';
    temp3['oldvalue']= previous.support_group;
    temp3['newvalue']= current.support_group;
    arr.push(temp3);
    }
    if(current.u_sla_definition.changes()){
      var temp4={};
     temp4['field']='u_sla_definition';
    temp4['oldvalue']= previous.u_sla_definition;
    temp4['newvalue']= current.u_sla_definition;
    arr.push(temp4);
    }
    gs.eventQueue('ba.notification.group', current, arr.push());

 

1 ACCEPTED SOLUTION

@Priyanka Chaud1 

try this

I have used .toString() whenever you are getting the value from current and previous object

Also note support_group is reference so it will give sysId so if you want to show group name then use getDisplayValue()

Same goes with install_status which is a choice type; if you simply get the value you will get choice value and not choice label; so I used getDisplayValue() there as well

var arr = [];
if (current.name.changes()) {
    var temp1 = {};
    temp1['field'] = 'name';
    temp1['oldvalue'] = previous.name.toString();
    temp1['newvalue'] = current.name.toString();
    arr.push(temp1);
}
if (current.install_status.changes()) {
    var temp2 = {};
    temp2['field'] = 'install_status';
    temp2['oldvalue'] = previous.install_status.getDisplayValue();
    temp2['newvalue'] = current.install_status.getDisplayValue();
    arr.push(temp2);
}
if (current.support_group.changes()) {
    var temp3 = {};
    temp3['field'] = 'support_group';
    temp3['oldvalue'] = previous.support_group.getDisplayValue();
    temp3['newvalue'] = current.support_group.getDisplayValue();
    arr.push(temp3);
}
if (current.u_sla_definition.changes()) {
    var temp4 = {};
    temp4['field'] = 'u_sla_definition';
    temp4['oldvalue'] = previous.u_sla_definition.toString();
    temp4['newvalue'] = current.u_sla_definition.toString();
    arr.push(temp4);
}

gs.eventQueue('ba.notification.group', current, JSON.stringify(arr));

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

View solution in original post

7 REPLIES 7

@Ankur Bawiskar I tried using event.parm1 instead of event.parm2 in email script and this is what i am getting in notification body:-

Field: install_status Old Value: [object Object] New Value: [object Object]

@Priyanka Chaud1 

try this

I have used .toString() whenever you are getting the value from current and previous object

Also note support_group is reference so it will give sysId so if you want to show group name then use getDisplayValue()

Same goes with install_status which is a choice type; if you simply get the value you will get choice value and not choice label; so I used getDisplayValue() there as well

var arr = [];
if (current.name.changes()) {
    var temp1 = {};
    temp1['field'] = 'name';
    temp1['oldvalue'] = previous.name.toString();
    temp1['newvalue'] = current.name.toString();
    arr.push(temp1);
}
if (current.install_status.changes()) {
    var temp2 = {};
    temp2['field'] = 'install_status';
    temp2['oldvalue'] = previous.install_status.getDisplayValue();
    temp2['newvalue'] = current.install_status.getDisplayValue();
    arr.push(temp2);
}
if (current.support_group.changes()) {
    var temp3 = {};
    temp3['field'] = 'support_group';
    temp3['oldvalue'] = previous.support_group.getDisplayValue();
    temp3['newvalue'] = current.support_group.getDisplayValue();
    arr.push(temp3);
}
if (current.u_sla_definition.changes()) {
    var temp4 = {};
    temp4['field'] = 'u_sla_definition';
    temp4['oldvalue'] = previous.u_sla_definition.toString();
    temp4['newvalue'] = current.u_sla_definition.toString();
    arr.push(temp4);
}

gs.eventQueue('ba.notification.group', current, JSON.stringify(arr));

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

TYSM it worked