Need help with "sc req item events" Business Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2011 12:44 PM
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);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2011 01:36 PM
You could change:
if (current.operation() == 'insert') {
gs.eventQueue("sc_req_item.inserted", current, gs.getUserID(), gs.getUserName());
}
To:
if (current.operation() == 'insert' || current.requested_for.changes()) {
gs.eventQueue("sc_req_item.inserted", current, gs.getUserID(), gs.getUserName());
}
Or just add another few lines to the end of the rule:
if (current.operation() != 'insert' && current.requested_for.changes()) {
gs.eventQueue("sc_req_item.inserted", current, gs.getUserID(), gs.getUserName());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2011 07:11 AM
It would be more reliable to trigger the requested by change event from a request table rule since that's really where the change is taking place. If you have the derived field (request.requested_by) on the requested item form and you only change the value in the derived field, the requested item record has not been changed so none of the rules will run.
You can enable the Debug Business Rule module to view the business rules running.
This model also covers the case where you have multiple items for a single request.
You can still call the same event, just make sure you pass the requested item glide records instead of current since current would be the request.
Would look something like:
//request rule when requested_by changes
var items = new GlideRecord("sc_req_item");
items.addQuery("request", current.sys_id);
items.query();
while (items.next()) {
gs.eventQueue("sc_req_item.inserted", items, gs.getUserID(), gs.getUserName());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2011 07:24 AM
Ok. Thank you for all your help.