- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 06:29 AM
Hi All,
Can Someone please help me on this Business rule I am working .I am creating a after business rule on a custom table called u_test_cmdb_ci and this runs when inserted or updated.
I want a field from another custom table called u_met_integration_maps . Please see the below code and suggest me the changes I need to do . I am getting result as undefined.
Log: METValue undefined
Code:
======
(function executeRule(current, previous /*null when async*/) {
var hierarchypath = current.u_hierarchypath;
var Max = new GlideRecord('u_met_integration_maps');
Max.addQuery('u_module','CMDBCI');
Max.addQuery('u_direction','Inbound [ System > MET ]');
Max.addQuery('u_mapped_sys_value', hierarchypath);
Max.query();
var r = Max.u_met_value;
gs.log("METValue "+r);
current.u_cmdb_class_name = r;
current.update();
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 07:09 AM
That indicates something is wrong with the query itself.
Check the field types and values closely to ensure what you are looking for is exactly what you need.
As a side test, can you build a filter on the u_met_integration_maps table to get a record using the same parameters/values?
E.g.
Module | is | CMDBCI AND
Direction | is | Inbound [ System > MET ] AND
Mapped sys value | is | (some value you know for hierarchy path)
Does that work from the list? If so, you could copy the query there and use an addEncodedQuery() method.
This video may help:
Video: Scripting Complex Queries Quickly

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 08:31 AM
The BR is only going to update the current record (the way you have it.)
If you want to update the other three records, you'll need to write a BR to update those records.
BTW, you should never use a current.update() in a before or after BR.
Reference:
Business Rules Best Practices - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 05:07 PM
Hi Chuck,
Please guide me or provide any sample script for setting value for 3 records in the table which I am running the BR which have same hierarchypath.
Regards,
Ravishankar G

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2017 05:57 AM
Sorry for the delay. I was OOO a lot last week for customer and personal.
The basic idea is that you need to get the records from the table and then update them accordingly.
Standard disclaimer: The following code is untested, requires review and potential modifications.
var rec = new GlideRecord('YOURTABLEHERE');
rec.addQuery('field', 'value'); // only get records where field=value
rec.query();
// loop through the records
while (rec.next()) {
// Do something like set active=false like this. rec.active = false;
rec.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 08:37 AM
Hi Chuck,
Could you please guide me or provide sample code on business rule for setting value for 3 records in table on which I am running BR.
Also , please suggest an alternate without using current.update();
Regards,
Ravi G