- 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 12:28 PM
Hi
Is the u_business_service_ci field have multiple values? And bsci.get('sys_id of record'),so make sure u r passing sys_id and not the string(current.u_business_service_ci.toString())
And usually it is not recommended to do glide record querying inside loop,so the best practice is to put the desired records in array and then query.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 01:06 PM
Can you please give a try with,
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.query();
while(rel.next()){
var srv = new GlideRecord('cmdb_ci_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:17 PM
Shishir - That didn't give the right results, returned with a false when it should have been a true.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 01:20 PM
Can we change this line and then try.
if (srv.u_sox_report_related)
to
if (srv.u_sox_report_related == true || srv.u_sox_report_related == false)