How to condition an approval email based on the approval assignment group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 11:35 AM
Need help writing the code:
I have two group approval requests in a workflow
I want each one to have a unique approval email
I want the condition to be defined based on the assignment group called in the current approval request generated
what is the correct way to write this code for an if conditon based on the catalog item name and assignment approver group?
script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 12:55 PM
Hello @Joshua Comeau ,
You can give a try to the script below and let me know how it works for you.
// Get the approval record
var approvalRecord = new GlideRecord('sysapproval_approver');
if (approvalRecord.get(current.sysapproval)) {
// Get the assignment group of the current approval
var assignmentGroup = approvalRecord.assignment_group.getDisplayValue();
// Check the catalog item name
var catalogItemName = approvalRecord.cat_item.name.getDisplayValue();
// Set the default email template
var emailTemplate = 'default_email_template';
// Check conditions and set the appropriate email template
if (catalogItemName == 'Oracle Access' && assignmentGroup == 'Group1') {
emailTemplate = 'oracle_access_group1_template';
} else if (catalogItemName == 'Oracle Access' && assignmentGroup == 'Group2') {
emailTemplate = 'oracle_access_group2_template';
} else if (catalogItemName == 'Other Catalog Item' && assignmentGroup == 'Group3') {
emailTemplate = 'other_catalog_item_group3_template';
}
// Set the email template in the approval record
current.setValue('email_template', emailTemplate);
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 05:41 AM
this code did not work I tried using more simpler method which is the below but it generates duplicate email
if (catalogItemName == 'Oracle Access' && assignmentGroup == 'Group1') {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 11:48 AM
Hello @Joshua Comeau ,
Please give a try to the script below and let me know how it works for you.
// Get the approval record
var approvalRecord = new GlideRecord('sysapproval_approver');
if (approvalRecord.get(current.sysapproval)) {
// Get the assignment group of the current approval
var assignmentGroup = approvalRecord.assignment_group.getDisplayValue();
// Check the catalog item name
var catalogItemName = approvalRecord.cat_item.name.getDisplayValue();
// Set the default email template
var emailTemplate = 'default_email_template';
// Check conditions and set the appropriate email template
if (catalogItemName == 'Oracle Access') {
if (assignmentGroup == 'Group1') {
emailTemplate = 'oracle_access_group1_template';
} else if (assignmentGroup == 'Group2') {
emailTemplate = 'oracle_access_group2_template';
}
} else if (catalogItemName == 'Other Catalog Item' && assignmentGroup == 'Group3') {
emailTemplate = 'other_catalog_item_group3_template';
}
// Set the email template in the approval record
current.setValue('email_template', emailTemplate);
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket