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.

Need help with "sc req item events" Business Rule

alhicks
Tera Guru

We need the "sc_req_item.inserted" event to also fire if the "Request.Requested_For", changes. So, we need it to fire when the Item is requested, like it does now but we also need it to fire if the request.requested_for changes to someone else, so they can also receive the notification. I tried changing the below Business Rule but ended up receiving duplicate notifications when the Item was opened.



if (current.operation() != 'insert' && current.comments.changes()) {
gs.eventQueue("sc_req_item.commented", current, gs.getUserID(), gs.getUserName());
}

if (current.operation() == 'insert') {
gs.eventQueue("sc_req_item.inserted", current, gs.getUserID(), gs.getUserName());
}

if (current.operation() == 'update') {
gs.eventQueue("sc_req_item.updated", current, gs.getUserID(), gs.getUserName());
}

if (current.operation() == 'update' && current.stage == "delivery") {
gs.eventQueue("sc_req_item.delivery", current, gs.getUserID(), gs.getUserName());
}

if (!current.assigned_to.nil() && current.assigned_to.changes()) {
gs.eventQueue("sc_req_item.assigned", current, current.assigned_to.getDisplayValue() , previous.assigned_to.getDisplayValue());
}

if (current.stage.changes()) {
gs.eventQueue("sc_req_item.change.stage", current, current.stage, previous.stage);
}

7 REPLIES 7

alhicks
Tera Guru

Thank you, I'll give it a try.


I tried it but seem to be having some problems still.

If I use the one below. The first email is firing 3 times.

if (current.operation() == 'insert' || current.request.requested_for.changes()) {
gs.eventQueue("sc_req_item.inserted", current, gs.getUserID(), gs.getUserName());
}


If I use the one below. The first email only fires once but when I change the request.requested_for on the Requested Item, it doesn't fire the email to the new requested for.

if (!current.operation() == 'insert' && current.request.requested_for.changes()) {
gs.eventQueue("sc_req_item.inserted", current, gs.getUserID(), gs.getUserName());
}


Brad Tilton
ServiceNow Employee
ServiceNow Employee

I messed up the syntax when I originally wrote that. For the second one, try:



if (current.operation() != 'insert' && current.request.requested_for.changes()) {
gs.eventQueue("sc_req_item.inserted", current, gs.getUserID(), gs.getUserName());
}


Hey, I tried again just using the below and it fires two emails. Any suggestions?

if (current.operation() != 'insert' && current.request.requested_for.changes()) {
gs.eventQueue("sc_req_item.inserted", current, gs.getUserID(), gs.getUserName());
}