Help with Event is not getting created!

gemini17
Kilo Guru

I created the business rule in the developer program, training.   I lost the original Marketing Event application, so I had to start all over and created a similar M_Events application.

My script for the business rule is:

function onAfter(current, previous) {

  //This function will be automatically called when this rule is processed.

  //Add event when attendee inserted

  if(current.operation() == 'insert' && current.marketing_event.changes()) {

  gs.eventQueue('x_19025_m_events_a_attendee.added', current,

  current.marketing_event, current.email);

  }

  //Add event when marketing event changes

  if(current.operation() == 'update' && current.marketing_event.changes()) {

  gs.eventQueue('x_19025_m_events_a_attendee.deleted', previous,

  previous.marketing_event, previous.email);

  gs.eventQueue('x_19025_m_events_a_attendee.added', current,

  current.marketing_event, current.email);

  }

  //Add event when attendee deleted

  if(current.operation() == 'delete') {

  gs.eventQueue('x_19025_m_events_a_attendee.deleted', current,

  current.marketing_event, current.email);

  }

}

when I try to add attendees< I get error:

Access to event 'x_19025_m_events_a_attendee.added' from scope 'M_Events_Application' has been refused. The event is not defined.

Any help is appreciated.

Kind regards

Danny Raj

15 REPLIES 15

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Danny,



Is the event "'x_19025_m_events_a_attendee.added" or "'x_19025_m_events_a.attendee.added" ? Can you show us a screenshot of the Event Registration record for this event?



Thanks,


Cory


Hi Cory:



The attendee table is: x_19025_m_events_a_attendee and therefore the event should be "x_19025_m_events_a_attendee.added".   I am not sure why the event is coming undefined.   Did you have a chance to look at my script.   can you find any mistakes, I might have missed.



Kind regards


Danny Raj


Hi Danny,



I suspect one issue here. I feel that you have created the event in particular application scope and you are accessing the event from the global scope since it is defind in other scope hence system is giving such error.



Steps to reproduce or resolve.



1. Select the application scope as global from the system setting (setting button top right where update set and other details is changed).


2. create a brand new event with the same in global scope.


3. use the event in the business rule. it should resolve your issue.



find_real_file.png



Hope this helps.



Regards,


Atul Kumar


Hey Corey:



Thanks, I changed in the script line: gs.eventQueue('x_19025_m_events_a_attendee.added' to gs.eventQueue('x_19025_m_events_a,attendee.added'.   It worked.


Can you explain, for future, what is the logic, behind defining the event based on the table name.   I appreciate your help.



Kind regards


Danny Raj


coryseering
ServiceNow Employee
ServiceNow Employee

Hi Danny,



In a scoped application, the name of your event should always start with your scope name. After that, it's up to you to decide what the name of the event will be when you create it, and what you will use it for. The Event Registry is where you go to create events.



Screen Shot 2016-04-26 at 9.11.38 AM.PNG



In the example above, I am creating an event named "x_spoon.my.spoon.event and I can have it relate to a table, or leave it as -- None --. If I relate it to a table, then later on when I write a Script Action that acts on the event, it will have easier access to a "current" record for that table.



The naming is mostly up to you. In this case, as part of the example training, the event name relates directly to what the event represents- a new record has been added to the "attendee" table. You could have named the event "x_19025_m_events_a.my.super.awesome.event" or "x_19025_m_events_a.whatever_i_want".   In any case, it will be your application's scope name, followed by a period, followed by whatever you want to call the event. Making it related to what the event represents- such as adding or deleting a record from a table- is a convention that makes sense.



Thanks,


Cory