Event registry issues/inquiry

jMarshal
Mega Sage
Mega Sage

Hi everyone -- hoping for some insight regarding a problem I'm having triggering an event to send an email notification.

I created an event called "sc_req_item.updated" and I modified the "Update Request Item" OOB Inbound Email Action to fire the event every time (see below):

 

gs.include('validators');

if (current.getTableName() == "sc_req_item" && current.canWrite()) {
    current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;

    var eventName = 'sc_req_item.updated';
    var event = new GlideEvent(eventName);
    event.fire();

    if (gs.hasRole("itil")) {
        if (email.body.assign != undefined)
            current.assigned_to = email.body.assign;

        if (email.body.priority != undefined && isNumeric(email.body.priority))
            current.priority = email.body.priority;
    }
    current.update();
}

 


...and this is the ONLY place where I am generating the event. I registered the event on the sc_req_item table and detailed that it is fired by the Inbound Email Action.

...but it is firing in the event log upon creation of a request item (and the email notification that I created is triggering)...even though the Inbound Email Action didn't process it (there was no inbound email to initiate that)...so I am very confused as to why/how this event is being queued/processed.

Is the event name in question perhaps "reserved" in some manner and firing automatically because its seeing the new record in the table as an "update" -- odd, but the only thing I can imagine which would do this.

Any thoughts/advice on what to do about this? I suppose I could always just change it to a different name to test my theory...but I'm hoping someone just knows what I'm doing wrong, so I can better understand what is happening.


TLDR = how can a new event that I created (not oob) fire on it's own (the code that I wrote to fire it is not running)?
1 ACCEPTED SOLUTION

-O-
Kilo Patron
Kilo Patron

Event names of the form <table name>.<operation>, where <operation> is either inserted or updated are reserved.

E.g. OOB business rule named "sc req item events" fires "your" event.

Get in the habit of naming customization using the u_ prefix to avoid collisions with out of the box stuff.

View solution in original post

5 REPLIES 5

Vijay Balotia1
Tera Guru

Hi @jMarshal,

 

"Update Request Item" inbound email action will only trigger when someone send an email to ServiceNow as reply email. if you make any update on RITM it will not trigger.

 

If you seeing 'sc_req_item.updated' event got triggered and you are able to see it in event log table then please check BR or script includes using query like script contain 'sc_req_item.updated'. if you find anything there then this is fired form there not from inbound email action.

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks
Vijay Balotia