- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2016 06:36 AM
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 : "
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2016 07:09 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2016 06:41 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2016 06:45 AM
tried it. Here are the results:
[DEBUG] x_43238_commission (updateInvoiceFields_before): business rule - update invoice id : null

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2016 06:48 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2016 07:00 AM