- 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:00 AM
HI Ravi
can u pls try tihs
(function executeRule(current, previous /*null when async*/) {
var hierarchypath = current.u_hierarchypath;
var Servertype = current.u_ci_server_type;
var Max = new GlideRecord('u_met_integration_maps');
gs.log("Running BR");
Max.addQuery('u_module','CMDBCI');
Max.addQuery('u_direction','Inbound [ System > MET ]');
Max.addQuery('u_mapped_sys_value', hierarchypath);
Max.query();
if(Max.next()){
var r = Max.u_met_value;
gs.log(Max.getRowCount()');
current.u_cmdb_class_name = Max.u_met_value;
current.update();
}
})(current, previous);

- 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:43 AM
Hi Ravi
Can you see in the log the message Running BR ?
Because if not probably the condition of the BR is not met and the BR not executed.
I would also check the values for the inputs of your query
Cheers
R0b0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 06:32 AM
Add if condition after .query();
if(Max.next()){
var r = Max.u_met_value;
gs.log("METValue "+r);
current.u_cmdb_class_name = r;
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 06:33 AM
Hi Ravi
First of all I would suggest to change the script to
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();
if(Max.next()){
gs.log(Max.sys_id);
var r = Max.u_met_value;
gs.log("METValue "+r);
current.u_cmdb_class_name = r;
current.update();
}
Check what it is the sys_id returned.
Cheers
R0b0