- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2015 10:28 AM
I have come to a road block here.I have a onAfter business rule which entirely depends on current.operation() and it is null. The business rule is firing.The first gs.info message logs:Business rule running: null 4f65a2676f9a0200b5919e0cbb3ee43b. Does not go beyond that.I am also attaching the image of business rule.Any direction will be helpful.I am on Fuji Patch 7.
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
gs.info("Business rule running: {0} {1}", current.operation(),current.sys_id);
if( current.operation() == "insert" ) {
gs.log('Insert rule running:', 'Location Sync Remote App Table');
insertToRemoteTable(current);
}
else if( current.operation() == "update") {
gs.log('Update rule running:', 'Location Sync Remote App Table');
updateOnRemoteTable(current);
}else if ( current.operation() == "delete") {
gs.log('Delete rule running:' , 'Location Sync Remote App Table');
deleteFromRemoteTable(current);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2015 12:16 PM
I don't believe that operation is available for an 'after' business rule.
I would suggest creating two separate business rules, with the insert and update only checked respectively.
(Other option is make it a before, but it could be a performance hit.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2015 02:17 PM
On which version is the demo instance you were able to see the the current.operation() logged.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2015 12:22 PM
Okay this works .. Just verified on my personal instance
function onAfter(current, previous) {
gs.info("Business rule running: {0} {1}", current.operation(),current.sys_id);
if(current.operation()=='insert')
{
gs.addInfoMessage("insert here");
}
if(current.operation()=='update')
{
gs.addInfoMessage("update here");
}
}
Not sure why you are getting null but the above code prints the messages as intended.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2015 02:09 PM
I tried Pradeep's code on demo ServiceNow and on my personal developer instance provided from https://developer.servicenow.com/app.do#!/dashboard and also my company's another instance.In all three instances I could see only one blue info message as attached.None for the operation info message :
Pradeep and Kalaiarasan,
Did you guys create the BS for cmn_location table?
Was the demo instance same as mine?
Thanks for your time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2015 08:14 PM
I could make this work by creating three separate business rules one each for 'insert', 'update' and 'delete' as Robert Pastore said.I could see that after each action only the right one BS is being triggered.
I assume the versions Kalaiarasan and Pradeep were using were different .I could see a lot of scripts with current.operation(). Could not see anywhere in the document that current.operation() is not available with 'after' BS.Lost one whole day over this.
Thanks guys! I believe in this community!!