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.

Why this inbound email script not working?

JordyZ
Mega Sage

Hi,

 

I have an inbound email script of reply type on the case table. The goal is to send a notification to the assignee whenever a case receives an E-mail (by anyone except the assignee itself).


This is the inbound email action script (the gs.warn returns true, but the event is not triggered):

(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
    var fromEmail = email.from + '';
    var assignedToEmail = current.assigned_to.email + '';
    var test = fromEmail != assignedToEmail;
    // Implement email action here
    if (test) {

        gs.warn('sending the event: ' + test);
        gs.eventQueue('sn_customerservice.case.update_assigned_to', current, current.assigned_to.email, current.number);
    }


})(current, event, email, logger, classifier);

The event is registered like this (should the "fired by" be configured?)

JordyZ_0-1701094223875.png

And finally the notification to the assignee is configured by taking that same event as activation trigger:

JordyZ_1-1701094323025.png

 

Why is the event in the script not triggered? Without it triggering, the notification won't work.


Thanks in advance

5 REPLIES 5

AshishKM
Kilo Patron
Kilo Patron

Hi @JordyZ ,

Are you getting gs.warn message in log, if not then change the If condition and check.

    if (fromEmail != assignedToEmail) {
        gs.warn('sending the event: ' + test);
        gs.eventQueue('sn_customerservice.case.update_assigned_to', current, current.assigned_to.email, current.number);
    }

-Thanks,

AshishKMishra


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hi @AshishKM ,

Yes the gs.warn message is in the log and it returns true. 

Seems all looks good. Can you try following

1.Notification is active - Just wanted to double check

2.Can you try trigger the same notification with another "valid event" - if this work, then we can say notification is working .

3.Try simulate/create another event(Make sure to be on right scope) and update your script/Notification accordingly.  And trigger notification.

 

Please share us your input, if you fixed in any other way .

 

Regards,

Luxo

Hi @Luxo Nadappan @AshishKM , thanks for replying. In the end, it was just a typo in the event name. Dumb mistake by me.

 

I have another question. Using the live_notification table, I'm creating a BR that triggers an event whenever @someone is mentioned in activity log. This one also not triggering the event.

 
 

JordyZ_3-1701181534552.png

It's the right event name this time and the notification is configured correctly. Any ideas?