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

sushantmalsure
Mega Sage
Mega Sage

Try following 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.<variable_name> == '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; 
 } 
}

I have added extra condition on line 7, just replace <variable_name> with correct variable name and make sure to use correct value of 'New' or 'new' or something else.

For example variable name is 'type' & value is 'new' then condition will look like following:

if ( record.cat_item.name.toString() == 'Email Distribution Lists' && record.variables.type == 'new')

 

 

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 just tried but didn't work. Didn't trigger the notification. 

Can you share sheenshot of condition and variable which you are thinking to add in condition along with actual value of new option ?

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Hi, 

This is the question with the value

EdxavierRobert_0-1689810802181.png

Here is the conditional builder to restrict only to this catalog item

EdxavierRobert_1-1689810984717.png