- 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 06:49 AM
Hello Ravi,
Have you manually checked in the table "u_met_integration_maps" returning records by adding filter condition, also please keep in mind you have to pass sys_id, if you are adding reference field in the addQuery condition.
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 07:33 AM
Thanks everyone , I was able to figure out as I was not doing correct query.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 07:35 AM
Glad you got it figured out Ravi. Can you share the specifics of the error and/or correction?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 07:44 AM
Hi Chuck,
Actually I am getting value set for a single matching query conditions , however I have 3 records having same "hierarchypath" .
this query should be seeing 3 records however when I tested by updating a single record field in this table , it is setting the value only for this record .
Please let me know how do I dynamically set the value for all matching records .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 07:47 AM
Change the if (Max.next())
to while (Max.next())
Keep in mind, you have a current.update() in that while loop, so it's going to update the current record three times. You may want to save that until after yyou get out of the loop and you've got the values from all three records.