sys_id in business rules return null

moserism
Kilo Contributor

In all of my business rules, I just discovered that current.sys_id is not being sent to the script include the business rule triggers. Here's an example of the business rules I'm using.

function onBefore(current, previous) {

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

      var id = current.sys_id;

      gs.debug("business rule - update invoice id : " + id);

      if (current.state == "draft" || current.state.nil() ) {

              var myInvoice = new InvoiceUtility();

              myInvoice.updateFields( id );

      }

}

I also tried with the .toString() method:

function onBefore(current, previous) {

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

      var id = current.sys_id.toString();

      gs.debug("business rule - update invoice id : " + id);

      if (current.state == "draft" || current.state.nil() ) {

              var myInvoice = new InvoiceUtility();

              myInvoice.updateFields( id );

      }

}

the gs.debug returns "business rule - update invoice id : "

1 ACCEPTED SOLUTION

I tested this on Fuji and on Helsinki and don't believe that before/query business rules actually know about current. I don't think they should either. The thing to note about query rules is they run before EVERY hit to the database for that table. lists, forms, reference fields, you name it, if the system is going to do a select statement from that table, the before query rule is run first. Normally this is used to do some filtering on the records before they are retrieved, not processing as in your case.



You may want to uncheck the QUERY checkbox and check INSERT or UPDATE instead? Perhaps?



Business Rules Best Practices - ServiceNow Wiki


View solution in original post

9 REPLIES 9

Chuck Tomasi
Tera Patron

Hi Michael,



How about this as a test.



function onBefore(current, previous) {


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


      var id = current.getValue('sys_id');


      gs.debug("business rule - update invoice id : " + id);


}


tried it. Here are the results:


[DEBUG] x_43238_commission (updateInvoiceFields_before): business rule - update invoice id : null


Well that's not good. It means current isn't current.



A question: What release of ServiceNow are you on?



A request: Please include a screenshot of the details of this business rule (all sections please.) We might be overlooking a simple form element.


I'm currently running: fuji-12-23-2014__patch13-hotfix1-05-26-2016_05-26-2016_1303



Here are the business rule settings:


Screen Shot 2016-07-25 at 9.50.46 AM.png


Screen Shot 2016-07-25 at 9.50.32 AM.png


Screen Shot 2016-07-25 at 9.59.53 AM.png



And here is the debug log:



Screen Shot 2016-07-25 at 9.53.57 AM.png