The CreatorCon Call for Content is officially open! Get started here.

How to condition an approval email based on the approval assignment group

Joshua Comeau
Kilo Sage

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

 

JoshuaComeau_0-1705088122910.png

 

what is the correct way to write this code for an if conditon based on the catalog item name and assignment approver group?

 

script:

var item=new GlideRecord('sc_req_item');
if (item.get(current.sysapproval) ){
    var name=item.cat_item.name;
    if (name=='Oracle Access'){
        answer=true;
   
            }
    else answer=true;
}

 

 

3 REPLIES 3

Aniket Chavan
Tera Sage
Tera Sage

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

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') {

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