BR notification on Visual task boards - new label

user034972342
Tera Contributor

Hi, I am trying to trigger an event inside of a BR that will send a notification to the task primary owner if a label/tag containing "planned" is added to a VTB card on Visual Task Board. The event/email is not getting triggered whenever I make a change on the VTB. Could anyone review the following:

 

I set up a BR to run on vtb_card table, After, insert

 

My event and the notification are also running on vtb_card and the notification will get sent to the task.primary_contact.

 

Business Rule:

Condition: Board = Team Name

 

 

(function executeRule(current, previous /*null when async*/ ) {

 

    var labelEntryGR = new GlideRecord('label_entry');

    labelEntryGR.addQuery('table', 'vtb_card');

    labelEntryGR.addQuery('table_key', current.sys_id);

    labelEntryGR.query();

    while (labelEntryGR.next()) {

        var labelGR = new GlideRecord('label');

        if (labelGR.get(labelEntryGR.label.sys_id)) {

            if (labelGR.name.indexOf('planning') !== -1) {

               

                var cardGR = new GlideRecord('vtb_card');

                if (cardGR.get(labelEntryGR.table_key)) {

               

                    gs.eventQueue('myevent, cardGR);

                }

            }

        }

    }

   

})(current, previous);

 

1 ACCEPTED SOLUTION

@user034972342 - Please add logger to understand the value you are receiving as a labelGR.name and check. Code looks good to me, I assume you have register the required event "myevent" on the table vtb_card. 


Thanks & Regards,
Vasanth

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@user034972342 

so what debugging did you perform by adding gs.info() statements?

you are not setting the recipient from script, how is the recipient set?

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

The recipient is sent in the notification setup. When to Send - Event is triggered Who to send: Users/Groups in task.primary_contact

 

I added gs.info() but they are not appearing in logs.... I don;t think BR is even getting triggered

 

(function executeRule(current, previous /null when async/) {
gs.info("start BR: " + current.sys_id);

var labelEntryGR = new GlideRecord('label_entry');

labelEntryGR.addQuery('table', 'vtb_card');

labelEntryGR.addQuery('table_key', current.sys_id);

labelEntryGR.query();

 

while (labelEntryGR.next()) {

gs.info("Process label_entry record: " + labelEntryGR.sys_id);

 

var labelGR = new GlideRecord('label');

if (labelGR.get(labelEntryGR.label.sys_id)) {

gs.info("Found label: " + labelGR.name);

 

if (labelGR.name.indexOf('planning') !== -1) {

gs.info("trigger event");

 

var cardGR = new GlideRecord('vtb_card');

if (cardGR.get(labelEntryGR.table_key)) {

gs.info("Found VTB Card: " + cardGR.sys_id + " - Triggering event 'myevent'");

gs.eventQueue('myevent', cardGR);

} else {

gs.info("No VTB Card found for label_entry.table_key: " + labelEntryGR.table_key);

}

} else {

gs.info("Label does not contain 'planning'.");

}

} else {

gs.warn("No label found: " + labelEntryGR.sys_id);

}

}

})(current, previous);

 

Vasantharajan N
Giga Sage
Giga Sage

@user034972342 - You missed a quote in gs.eventQueue. 

 

var labelEntryGR = new GlideRecord('label_entry');

labelEntryGR.addQuery('table', 'vtb_card');

labelEntryGR.addQuery('table_key', current.sys_id);

labelEntryGR.query();

while (labelEntryGR.next()) {

    var labelGR = new GlideRecord('label');

    if (labelGR.get(labelEntryGR.label.sys_id)) {

        if (labelGR.name.indexOf('planning') !== -1) {

            var cardGR = new GlideRecord('vtb_card');

            if (cardGR.get(labelEntryGR.table_key)) {

                gs.eventQueue('myevent', cardGR); // You missed a quote

                }

            }

        }

    }

 


Thanks & Regards,
Vasanth

I added the missing quote, but still not getting triggered.