- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 04:31 AM
Hi All,
Can someone please help with the below Business rule .When checking the logs it shows as rows retrieved: 0 . Please guide.
(function executeRule(current, previous /*null when async*/) {
var sci = current.u_sourceci;
var rel = new GlideRecord('u_maximo_cmdb_ci');
rel.addQuery('u_cinum', sci);
rel.addQuery('u_hierarchypath', 'OPERATING SYSTEM \ AIX');
rel.addQuery('u_cmdb_class_name', 'u_cmdb_ci_logical_partition');
rel.query();
gs.log("rows retrieved :"+rel.getRowCount());
if(rel.next()){
gs.log("HELLO IF");
current.u_aixlpar = 'True';
}
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 05:53 AM
Found it! It's definitely the backslash. It's a special character in Javascript that says 'the next character goes with this like \n, \t, etc.' To get it to work, change your query to use double backslash. That tells Javascript that the next character is a backslash, not a special character;
u_hierarchypath=OPERATING SYSTEM \\ AIX^u_cmdb_class_name=u_cmdb_ci_logical_partition
Sorry, I should have seen this earlier. It's been a crazy week.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 04:46 AM
Hi Chuck,
Please let me know if this is fine.
var sci = current.u_sourceci;
var rel = new GlideRecord('u_maximo_cmdb_ci');
rel.addQuery('u_cinum', sci);
rel.addEncodedQuery('u_hierarchypath', 'OPERATING SYSTEM \ AIX');
rel.addQuery('u_cmdb_class_name', 'u_cmdb_ci_logical_partition');
rel.query();
gs.log("rows retrieved :"+rel.getRowCount());
if(rel.next()){
gs.log("HELLO IF");
current.u_aixlpar = 'True';
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 04:51 AM
I suspect the backslash is getting in the way. Build the filter on the list first then copy the query and use it in the addEncodedQuery() method as described in this video.
Video: Scripting Complex Queries Quickly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 04:58 AM
Hi Chuck,
I tried doing filter and it returned 5 records in table.
u_hierarchypath=OPERATING SYSTEM \ AIX^u_cmdb_class_name=u_cmdb_ci_logical_partition . I used this in my script as below. Still not working.
Sxript:
======
(function executeRule(current, previous /*null when async*/) {
var sci = current.u_sourceci;
gs.log("source CI :"+sci);
var rel = new GlideRecord('u_maximo_cmdb_ci');
rel.addQuery('u_cinum', sci);
rel.addEncodedQuery('u_hierarchypath=OPERATING SYSTEM \ AIX^u_cmdb_class_name=u_cmdb_ci_logical_partition');
rel.query();
gs.log("rows retrieved :"+rel.getRowCount());
gs.log("Result :"+rel.getEncodedQuery());
if(rel.next()){
gs.log("HELLO IF");
current.u_aixlpar = true;
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 05:03 AM
So you got 5 records with the two filters, but I'm seeing three filters in your script (with the additional addQuery().) Can you try this in your script and see how many records it gets back?
(function executeRule(current, previous /*null when async*/) {
// var sci = current.u_sourceci;
// gs.log("source CI :"+sci);
var rel = new GlideRecord('u_maximo_cmdb_ci');
// rel.addQuery('u_cinum', sci);
rel.addEncodedQuery('u_hierarchypath=OPERATING SYSTEM \ AIX^u_cmdb_class_name=u_cmdb_ci_logical_partition');
rel.query();
gs.log("rows retrieved :"+rel.getRowCount());
gs.log("Result :"+rel.getEncodedQuery());
if(rel.next()){
gs.log("HELLO IF");
current.u_aixlpar = true;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 04:39 AM
True/false fields can be set using the boolean value (no quotes, that's a string.)
(function executeRule(current, previous /*null when async*/) {
var sci = current.u_sourceci;
var rel = new GlideRecord('u_maximo_cmdb_ci');
rel.addQuery('u_cinum', sci);
rel.addQuery('u_hierarchypath', 'OPERATING SYSTEM \ AIX');
rel.addQuery('u_cmdb_class_name', 'u_cmdb_ci_logical_partition');
rel.query();
gs.log("rows retrieved :"+rel.getRowCount());
if(rel.next()){
gs.log("HELLO IF");
current.u_aixlpar = true;
}
})(current, previous);