onAfter Business rule: current.operation() is null

tantony
Mega Guru

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.

location_bs_1.pnglocation_bs_2.png

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);

  }

}

1 ACCEPTED SOLUTION

rob_pastore
ServiceNow Employee
ServiceNow Employee

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


View solution in original post

13 REPLIES 13

Kalaiarasan Pus
Giga Sage

I may be wrong here but is there any function as gs.info ?


Shouldn't it be gs.addInfoMessage ?


Hi Kalai,



Yes there is a function gs.info. Please check section 4.3 for more info.


http://wiki.servicenow.com/index.php?title=Scoped_GlideSystem_API_Reference#info.28String_message.2C...


Never used that one before I just saw the page after replying


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Tessy,



If you are creating this BR as part of scoped application then remove the statement gs.log as this is not supported as part of scoped application. Try gs.info or gs.debug for scoped application.



Please let me know if you have any questions.