- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2023 04:19 PM
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.
Any suggestion?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2023 05:14 PM
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;
}
}
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2023 04:36 PM
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')
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2023 04:44 PM
Hi, I just tried but didn't work. Didn't trigger the notification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2023 04:45 PM
Can you share sheenshot of condition and variable which you are thinking to add in condition along with actual value of new option ?
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2023 04:56 PM
Hi,
This is the question with the value
Here is the conditional builder to restrict only to this catalog item