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

-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.

-O-
Kilo Patron
Kilo Patron

Also, you don't need to define an event in the Registry to be able to fire it.

The only use for defining an event in the registry is to be able to select it in drop-downs (like the Event name field on a Notification record, or the Event name field on a Script Action record).

So just because you don't see the event in the Registry, it does not mean that it is not already in use.

Hence the better practice of naming your stuff using the u_ prefix.

Thanks for the info! I had a feeling this was oob functionality that I was not fully understanding.

I do need it in the registry so that I can trigger a notification on it, in this case...but knowing that it doesn't need to be in the registry to exist will absolutely help me as I go forward.

Also, LOL @ the quotes on "my" event! So true! Thanks again 🙂

You're most welcome!

🙂