- 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-06-2018 11:54 PM
Hi,
grr.Query(); would be grr.query();
I ran below test script and it worked fine
var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('child', '829e953a0ad3370200af63483498b1ea');
gr.query();
if(gr.next()){
gs.print(gr.child.operational_status.getDisplayValue());
}
Please mark my answer correct if it helped you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 12:06 AM
The script is for transform, this is my requirement
but when i update the parent choice field to "retired" it should check for whether the child choice field value is in "Retired" status or not.
and if it finds as"retired" only then it can update the parent choice field with "retired" status otherwise it should skip or ignore

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 12:13 AM
Yes,
I understand your requirement, however the syntax you are using is not correct.
grr.Query(); would be replaced by grr.query(); Try below
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;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 12:28 AM
I tried below script it didn't work
if(action=="update" && source.u_operational_status=="Retired")
{
var grr=new GlideRecord("cmdb_rel_ci");
grr.addQuery("parent","source.u_operational_status");
grr.query();
while(grr.next())
{
gs.log(grr.child.operational_status.getDisplayValue());
if(grr.child.operational_status.getDisplayValue()!="Retired")
{
ignore=true;
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 01:09 AM
Hi,
I found one more issue in your script
grr.addQuery("parent", "source.u_operational_status"); would be grr.addQuery("parent",source.u_operational_status);
First script to try :
if(action=="update" && source.u_operational_status=="Retired")
{
var grr=new GlideRecord("cmdb_rel_ci");
grr.addQuery("parent",source.u_operational_status);
grr.query();
while(grr.next())
{
gs.log(grr.child.operational_status.getDisplayValue());
if(grr.child.operational_status.getDisplayValue()!="Retired")
{
ignore=true;
}
}
}
second step 2 try
if(action=="update" && source.u_operational_status=="Retired")
{
var grr=new GlideRecord("cmdb_rel_ci");
grr.addEncodedQuery("parent="+source.u_operational_status+"^child.operational_status!=6");
grr.query();
while(grr.next())
{
ignore=true;
}
}