Email Notification - Advance Conditions

Edxavier Robert
Mega Sage

Hi, 

I am trying to use the Advance Condition on an approval email notification to restrict the notification to only send out when a specific catalog item is submitted. This is the code that I am using and is currently working: 

var record = new GlideRecord('sc_req_item'); 
var sysApprovalSysId = current.sysapproval;
record.addQuery('sys_id', sysApprovalSysId); 
record.query(); 
if (record.next()) 
{ 
 if ( record.cat_item.name.toString() == 'Email Distribution Lists')
 { 
  gs.log('Email Notification for: Email Distribution List: '+record.cat_item.name.toString()+'\nStatus: True','Email test'); 
  answer = true; 
 } 
 else 
 { 
  gs.log('Email Notification for: Email Distribution List: '+record.cat_item.name.toString()+'\nStatus: False','Email test'); 
  answer = false; 
 } 
}

But now I wanted to include into the code the answer to one of the variables. I have a question on the form where the user needs to select between New or Change, if they select 'New' I want to send this notification. 

 

I was trying to use the conditional builder but I can't get to the variable level, only to the catalog item name.

EdxavierRobert_0-1689808763282.png

 

Any suggestion? 

1 ACCEPTED SOLUTION

Do not add anything in condition builder just add below advance condition script

var record = new GlideRecord('sc_req_item'); 
var sysApprovalSysId = current.sysapproval;
record.addQuery('sys_id', sysApprovalSysId); 
record.query(); 
if (record.next()) 
{ 
 if ( record.cat_item.name.toString() == 'Email Distribution Lists' && record.variables.new_or_change == 'New')
 { 
  gs.log('Email Notification for: Email Distribution List: '+record.cat_item.name.toString()+'\nStatus: True','Email test'); 
  answer = true; 
 } 
 else 
 { 
  gs.log('Email Notification for: Email Distribution List: '+record.cat_item.name.toString()+'\nStatus: False','Email test'); 
  answer = false; 
 } 
}
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

View solution in original post

7 REPLIES 7

Do not add anything in condition builder just add below advance condition script

var record = new GlideRecord('sc_req_item'); 
var sysApprovalSysId = current.sysapproval;
record.addQuery('sys_id', sysApprovalSysId); 
record.query(); 
if (record.next()) 
{ 
 if ( record.cat_item.name.toString() == 'Email Distribution Lists' && record.variables.new_or_change == 'New')
 { 
  gs.log('Email Notification for: Email Distribution List: '+record.cat_item.name.toString()+'\nStatus: True','Email test'); 
  answer = true; 
 } 
 else 
 { 
  gs.log('Email Notification for: Email Distribution List: '+record.cat_item.name.toString()+'\nStatus: False','Email test'); 
  answer = false; 
 } 
}
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Hi, I don't have anything in the conditional builder. I just added the code into the advance conditional. But is not working. 

Hi, now is working. Thanks for your help.