- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2018 11:19 PM
need to get the childs "operational status" of cmdb_ci_appl table
i used the below script but i couldn't get the value of child, its showing undefined in gslog.
was my script correct?
if(source.u_operational_status=="Retired")
{
var grr=new GlideRecord("cmdb_rel_ci");
grr.addQuery("parent","source.u_operational_status");
grr.Query();
while(grr.next());
{
if(grr.child.operational_status.getDisplayValue()!="Retired")
{
gs.log(grr.child.operational_status.getDisplayValue());
ignore=true;
}
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 03:28 AM
Did you check the source values? They must be 1:1.
Hmm, lets simplify this more.
if(action == 'update' && source.u_operational_status == 'Retired'){
var grr = new GlideRecord('cmdb_rel_ci');
grr.addQuery('parent.name', source.u_name);
grr.addQuery('child.operational_status', '!=', '6');
grr.query();
gs.log('QUERY: current rows for ' + source.u_name + 'with non-retired childs is ' + grr.getRowCount());
gs.log('QUERY: ' + source.u_name + ' ' + source.u_operational_status);
if(grr.next()){
gs.log('QUERY: Active child found! Ignore');
ignore = true;
}else{
gs.log('QUERY: No active childs found! Do not ignore!');
ignore = false;
}
}
}
If you run the transform and check the logs where message contains 'QUERY:' what does it log?
If nothing, then you need to check the values that are in your source table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 01:39 AM
i tried both the script still the parent(cmdb_ci_appl) is getting updated when the child is not "Retired"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 01:43 AM
Jidesh,
what is source.u_operational_status data type ? is it reference or string because, it is confusing
if(action=="update" && source.u_operational_status=="Retired")
Above you are evaluating against =="Reitred"
grr.addQuery("parent",source.u_operational_status);
Here you are trying to evaluate against a reference field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 02:13 AM
no its choice field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 03:19 AM
Hi Please try below
if(action=="update" && source.u_operational_status=="Retired")
{
gs.log('OPerational Status from source'+ source.u_operational_status);
var grr=new GlideRecord("cmdb_rel_ci");
grr.addEncodedQuery("parent="+source.u_name+"^child.operational_status!=6");
grr.query();
while(grr.next())
{
ignore=true;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 07:57 AM
i tired the above script it didnt work..
i need to get the child of only the application which i have updated,not the entire cmdb_rel_ci
if suppose i update the application to "retired" it should check only that applications child records not the entire cmdb_rel_ci
i tired with below script it checks for every child records..
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if(action == 'update' && source.u_operational_status == 'Retired'){
var gr = new GlideRecord('cmdb_ci_appl');
gr.addQuery('name', source.u_name);
gr.query();
while(gr.next()){
gs.log("entry");
var grr = new GlideRecord('cmdb_rel_ci');
grr.addQuery('parent', gr.sys_id);
grr.addQuery('parent.name',source.u_name);
grr.addQuery('child.operational_status', '!=', '6');
grr.query();
if(grr.next()){
gs.log("false");
ignore = true;
}else{
gs.log("before true");
ignore = false;
}
}
}
})(source, map, log, target);