Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Error creating a notification.

tomaslindev
Mega Guru

Hello everyone,

 

Currently in our instance there are some items of multi SC_Task type, which I have seen are evaluated at the notification level through this code:

 

var reqItemSysId = current.request_item.sys_id;
var variables = {};

var itemOptions = new GlideRecord('sc_item_option_mtom');
itemOptions.addQuery('request_item', reqItemSysId);
itemOptions.query();

while (itemOptions.next()) {
    variables[itemOptions.sc_item_option.item_option_new.name] = itemOptions.sc_item_option.value;
}

if (variables['multitask'] == 'true'){
	answer = true;
}else{
	answer = false;
}

 

The fact is that I have to create a notification that is sent when an "additional comment" is added to the parent RITM and it is sent to all the assigned groups (which are usually several and different from those of the parent RITM) to each of the "child SC_Tasks". For this I have created the notification, a BR and an event that I leave here, but I can't get it to work, any ideas.

 

Notification:

 

tomaslindev_0-1764538692811.png

tomaslindev_3-1764538825538.png

 

 

Event:

 

tomaslindev_1-1764538733460.png

 

 

BR:

 

tomaslindev_2-1764538756418.png

 

(function executeRule(current, previous) {

    if (current.additional_comments == previous.additional_comments)
        return;

    
    var vars = {};
    var opt = new GlideRecord('sc_item_option_mtom');
    opt.addQuery('request_item', current.sys_id);
    opt.query();
    while (opt.next()) {
        vars[opt.sc_item_option.item_option_new.name] = opt[opt.sc_item_option.value];
    }
    if (String(vars['multitask']).toLowerCase() !== 'true')
        return;

   
    var child = new GlideRecord('sc_task');
    child.addQuery('request_item', current.sys_id);
    child.query();

    while (child.next()) {
        if (child.assignment_group) {
            gs.eventQueue(
                'atc.ritm.multitask.comment_added', 
                child,
                current.additional_comments,
                ''
            );
        }
    }

})(current, previous);

 

Thank you very much in advance and greetings.

0 REPLIES 0