Can someone help me edit my advance condition script for email notification?

yjeon92
Tera Contributor
Hello Everyone,
 
I am trying to create an email notification where the opened by person's business unit will send the email to the recipient group that correlates to the business unit.  This script is my advance condition.  I am wondering why the email notification is not notifing anyone:
 
function() {
    var demand = new GlideRecord('dmn_demand');
    if (demand.get(current.demand)) {
       
        var openedByUser = new GlideRecord('sys_user');
        if (openedByUser.get(demand.opened_by)) {
           
            var department = new GlideRecord('cmn_department');
            if (department.get(openedByUser.department)) {
                var businessUnit = department.business_unit.name;
                var recipientGroups;
               
                switch(businessUnit) {
                    case 'HR':
                        recipientGroups = 'HR Team';
                        break;
                    case 'Audit':
                        recipientGroups = 'Audit Team';
                        break;
                    case 'Account Receivable':
                        recipientGroups = 'Account Receivable Team';
                        break;
                    case 'Account Payable':
                        recipientGroups = 'Account Payable Team';
                        break;
                    // Add more cases for other business units if needed
                    default:
                        recipientGroups = 'HelpDesk';
                }
               
                current.sysevent_email_action.recipient_groups = recipientGroups;
            }
        }
    }
})();
2 REPLIES 2

SanjivMeher
Kilo Patron
Kilo Patron

Not sure if you can use something like current.sysevent_email_action.recipient_groups. Is there a possibility to use events instead so that you can run this logic in a Business rule and then pass the group sysid in an event?

 

Also you are passing name of the group instead of sysid in below line. 

current.sysevent_email_action.recipient_groups = recipientGroups;


Please mark this response as correct or helpful if it assisted you with your question.

Appanna M
Tera Guru

Hello @yjeon92 ,

 

Can you add few debug logs to your code and try once.

 

(function() {
    var demand = new GlideRecord('dmn_demand');
    if (demand.get(current.demand)) {
        var openedByUser = new GlideRecord('sys_user');
        if (openedByUser.get(demand.opened_by)) {
            var department = new GlideRecord('cmn_department');
            if (department.get(openedByUser.department)) {
                var businessUnit = department.business_unit.name;
                var recipientGroups;
                switch(businessUnit) {
                    case 'HR':
                        recipientGroups = 'HR Team';
                        break;
                    case 'Audit':
                        recipientGroups = 'Audit Team';
                        break;
                    case 'Account Receivable':
                        recipientGroups = 'Account Receivable Team';
                        break;
                    case 'Account Payable':
                        recipientGroups = 'Account Payable Team';
                        break;
                    // Add more cases for other business units if needed
                    default:
                        recipientGroups = 'HelpDesk';
                }
                gs.info('Recipient Groups: ' + recipientGroups);
                current.sysevent_email_action.recipient_groups = recipientGroups;
            } else {
                gs.info('Department record not found for user: ' + openedByUser.getDisplayValue());
            }
        } else {
            gs.info('Opened by user record not found for demand: ' + demand.getDisplayValue());
        }
    } else {
        gs.info('Demand record not found');
    }
})();

 

Please Mark My Answer as Helpful and Accept as Solution, if you find this article helpful or resolves your issue.