Notification

Snehal
Tera Expert

Hi team ,

I have one requirement where i need the customise subject including short description like mentioned below 

email.setSubject('<div> Request'+ getritm.request.number +' was created - ' + getritm.cat_item.getDisplayValue() + '</div>');
and i want to complete this by using single email script and i have created one script i am mentioning below and its working fine and using this only additional requirement is that i want to add customize subject for other notifications also like for (Request was opened ,Request Rejected ,Request was completed ) but i am not able to add the if else condition for every notification.
 
(function runMailScript(current, template, email, email_action, event) {

var getritm = new GlideRecord('sc_req_item');
getritm.addQuery('request', current.sys_id);
getritm.query();
if (getritm.next()) {
email.setSubject('<div> Request '+ getritm.request.number +' was created - ' + getritm.cat_item.getDisplayValue() + '</div>');

}

})(current, template, email, email_action, event);
 
 
 
Thank You in Advance !
1 ACCEPTED SOLUTION

Anirudh Pathak
Mega Sage

Hi @Snehal ,

In order to accommodate in a single email script you will require to get the name of the notification using "email_action" object present in the email script  and then put your logic in "if and else" blocks. 

Here is a sample code - 

if(email_action.name == 'Request was opened') {
   var getritm = new GlideRecord('sc_req_item');
   getritm.addQuery('request', current.sys_id);
   getritm.query();
   if (getritm.next()) {
       email.setSubject('<div> Request '+ getritm.request.number +' was created - ' + getritm.cat_item.getDisplayValue() + 
       '</div>');
  }
}

else if(email_action.name == 'Request Rejected') {
// put your code to run on this condition
}

else if(email_action.name == 'Request was completed') {
// put your code to run on this condition
}

else {
// your code
}

 

View solution in original post

3 REPLIES 3

Anirudh Pathak
Mega Sage

Hi @Snehal ,

In order to accommodate in a single email script you will require to get the name of the notification using "email_action" object present in the email script  and then put your logic in "if and else" blocks. 

Here is a sample code - 

if(email_action.name == 'Request was opened') {
   var getritm = new GlideRecord('sc_req_item');
   getritm.addQuery('request', current.sys_id);
   getritm.query();
   if (getritm.next()) {
       email.setSubject('<div> Request '+ getritm.request.number +' was created - ' + getritm.cat_item.getDisplayValue() + 
       '</div>');
  }
}

else if(email_action.name == 'Request Rejected') {
// put your code to run on this condition
}

else if(email_action.name == 'Request was completed') {
// put your code to run on this condition
}

else {
// your code
}

 

Thank You ! Its really helped me .

Hi @Snehal  ,

Please mark it as accept solution if it resolved your issue. 

Thank you!