- 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 07:53 AM
Hi chuck ,
Actually I am not looking for updating the same record for 3 times , I am seeing 3 records with same "hierarchypath" so I want value to set for 3 different records which are having different CI number.
Please let me know if while(Max.next()) can do that ?
Also , please suggest whether it is recommended to use current.update(); as I am using after (insert, update) business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 08:09 AM
Hi Chuck,
I tried with While loop , it is still setting the value for only single record .
It is retrieving only 1 record for which I manually updated a field in that table , but we have 2 other records having same "hierarchypath" .
Please suggest.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 08:14 AM
Just so I'm clear, your getRowCount() is stating that 3 records were found, but the while loop is only running once?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 08:23 AM
Hi Chuck,
Rowcount is returning only 1 value and I want 3 values to be returned , please suggest
Regards,
Ravi G
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 08:26 AM
Hi Chuck,
getRowcount is returning only 1 value as the table which I am doing the query has only 1 entry . However the target table on which this BR is running has 3 records and I want those 3 to be having the value set which has same "hierarchypath"