BR doesn't trigger a notification

ronro2
Tera Contributor

Hello beautiful community!

I have a Business Rule that is based on sc_request for the sake of the notification. 

What I need to do is to trigger it based on the choice of a certain catalog item's multiple choice variable called 'requested_resource_type'. So when the user chooses 'technical_project_resource' in 'requested_resource_type' it should trigger the notification.

Here is my BR code: 

// Business Rule: Trigger Notification for teknisk_resursprojekt
// When to run: After Insert/Update

(function executeRule(current, previous /*null when async*/) {
    // Kontrollera om cat_item har rätt sys_id
    if (current.cat_item == '0f0278598c2a1e10ebb6ef259418f246') {
        // Hämta relaterade sc_req_item-poster
        var gr = new GlideRecord('sc_req_item');
        gr.addQuery('request', current.sys_id);
        gr.query();
        while (gr.next()) {
            // Kontrollera om användaren valt "technical_project_resource" i variabel 'requested_resource_type'
            var selectedResources = gr.variables.requested_resource_type; // Variabelvärde
            if (selectedResources && selectedResources.indexOf('technical_project_resource') !== -1) {
                // Trigga eventet 'teknisk_projektresurs'
                gs.eventQueue('teknisk_projektresurs', 'custom@email.com', current.requested_for.email, '');
            }
        }
    }
})(current, previous);


The problem; is that it doesn't trigger anything. The requested_for should have gotten the email, but nothing is sent. I've tested with my own custom email in the eventQueue line, but it doesn't trigger to that one either. 

What am I doing wrong? Here is the configuration for the BR:

ronro2_0-1736256511347.png


Here is the configuration for the notification: 

ronro2_1-1736256625971.png

 

ronro2_2-1736256688665.png

 


Thanks in advance! 😎




1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@ronro2 

your BR script is wrong

update as this ->you should query RITM to get the catalog item name

(function executeRule(current, previous /*null when async*/ ) {
    // Kontrollera om cat_item har rätt sys_id

    var ritm = new GlideRecord('sc_req_item');
    ritm.get('request', current.sys_id);
    if (ritm.cat_item == '0f0278598c2a1e10ebb6ef259418f246') {
        // Kontrollera om användaren valt "technical_project_resource" i variabel 'requested_resource_type'
        var selectedResources = ritm.variables.requested_resource_type; // Variabelvärde
        if (selectedResources && selectedResources.indexOf('technical_project_resource') !== -1) {
            // Trigga eventet 'teknisk_projektresurs'
            gs.eventQueue('teknisk_projektresurs', current, 'custom@email.com', ritm.requested_for.email);
        }
    }

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

@ronro2 

then event should trigger

Did you check any error when event triggered?

eventQueue link looks fine to me

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Instead of Current you can use "null".