- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 11:10 AM
So, I've tried to piece together scripts that I've used before for this but could really use some help.
On a Change [change_request], there is a field [u_business_service_ci] that references one or many CMDB Business Services [cmdb_ci_service]. A Business Service is then related to one or more Servers [cmdb_ci_server] through the CI Relationship table [cmdb_rel_ci] (Parent is [cmdb_ci_service], Type is [Owns::Owned by], Child is [cmdb_ci_server]). On the referenced Servers, there is a True/False field called SOX Report Related [u_sox_report_related]. When a Change is submitted, on the workflow I need an If activity script that checks through all of the Change --> Business Services --> Servers to see if that checkbox is present for at least one and return true.
This is what I've came up with but to no surprise it isn't working. Any ideas?
answer = ifScript();
function ifScript() {
var result = false;
var list = current.u_business_service_ci.toString();
var listArr = list.split(',');
for (var key in listArr) {
var bsci = new GlideRecord('cmdb_ci_service');
if (bsci.get(listArr[key])) {
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('parent', bsci.getUniqueValue());
rel.addQuery('type.name', "Owns::Owned by");
rel.addQuery('parent.sys_class_name', "cmdb_ci_service");
rel.query();
var ciIds = [];
if (rel.get(listArr[ciIds])) {
var srv = new GlideRecord('cmdb_ci_server');
if (srv.u_sox_report_related) {
return true;
}
}
return result;
}
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2018 03:41 PM
I think, I got this, we are returning the result within for loop that's why, i believe return will break the for loop, can we put the return result outside of for loop and try.
answer = ifScript();
function ifScript() {
var result = false;
var list = current.u_business_service_ci.toString();
gs.log('****** Business Services List **** : ' + list);
var listArr = list.split(',');
for (var key=0; key < listArr.length; key++) {
var bsci = new GlideRecord('cmdb_ci_service');
if (bsci.get(listArr[key])) {
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('parent', bsci.getUniqueValue());
rel.addQuery('type.name', "Owns::Owned by");
rel.query();
while(rel.next()){
var srv = new GlideRecord('cmdb_ci_win_server');
if(srv.get('sys_id', rel.child)){
if (srv.u_sox_report_related)
return true;
}
}
}
}
return result;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 01:23 PM
Interesting... it results in False as well.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 01:37 PM
okay, few changes (I don't think we need to do GlideRecord on cmdb_ci_service table), Can we put some logs and see till where it flow?
function ifScript() {
var result = false;
var list = current.u_business_service_ci.toString();
var listArr = list.split(',');
for (var key in listArr) {
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('parent', listArr[key]);
rel.addQuery('type.name', "Owns::Owned by");
rel.query();
while(rel.next()){
gs.log('***********Get REL RECORDS************');
var srv = new GlideRecord('cmdb_ci_server');
if(srv.get('sys_id', rel.child)){
gs.log('***********Get SRV RECORDS************');
if (srv.u_sox_report_related == 'true' || srv.u_sox_report_related == 'false') {
gs.log('***********Found u_sox_report_related RECORDS************');
gs.log('u_sox_report_related in IF' + u_sox_report_related );
return true;
}
else{
gs.log('***********No u_sox_report_related RECORDS************');
gs.log('u_sox_report_related in ELSE' + u_sox_report_related );
}
}
}
return result;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 03:36 PM
Shishir - Still returning false. I can seem to find any logs though... I went to the Workflow Context and under Workflow Log there is nothing resembling our logs in the Message. Is that right? I even tried moving the log to the very first line and nothing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 03:38 PM
you can see the logs here.
System logs -> Script Log Statements
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 04:00 PM
Ah... there was an issue but we got some logs now:
02/01/2018 03:57 PM Information ***********Get REL RECORDS************
02/01/2018 03:57 PM Information ***********Get SRV RECORDS************
02/01/2018 03:57 PM Information ***********No u_sox_report_related RECORDS************
02/01/2018 03:57 PM Information u_sox_report_related in ELSEundefined