- 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:57 AM
Ah, I see. And I expect that you have a source name field that's a coalescence field for the name in application table, correct?
if(action == 'update' && source.u_operational_status == 'Retired'){
var gr = new GlideRecord('cmdb_ci_appl');
gr.addQuery('name', source.name);
gr.query();
while(gr.next()){
var grr = new GlideRecord('cmdb_rel_ci');
grr.addQuery('parent', gr.sys_id);
grr.query();
while(grr.next()){
if(grr.child.operational_status == '6') {
gs.log(grr.child.operational_status.getDisplayValue());
ignore = false;
}else{
ignore = true;
}
}
}
}
Here the whole process is:
1. Check if update and source operation status is 'Retired';
2. Find a matching Application.
3. Find a relation where the parent is the application.
4. Check if the childs operational status is 'Retired'.
5. If it's not then ignore this update as parent can't be 'Retired' if child is not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 02:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 02:48 AM
Could you check the source table and what is the value (name) of the Operational Status and name field in there?
/*if the source field is u_operational_status and the source name is u_name, then this should be OK.
*/
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()){
var grr = new GlideRecord('cmdb_rel_ci');
grr.addQuery('parent', gr.sys_id);
grr.addQuery('child.operational_status', '!=', '6');
grr.query();
if(grr.next()){
ignore = true;
}else{
ignore = false;
}
}
}
I originally missed u_name in the gr query.
Also the while loop could change the ignore to be wrong in your case as it looped through all the childs.
I modified this to also query on the relationship table that operational status is not Retired.
If something is found, then the update is ignored as there's a child that isn't retired. Otherwise it's Ok to retire the parent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 02:59 AM
still its updating the parent operational status to retired even when the childs operational status is not in Retired
- 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.