- 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 05:53 AM
if i change the value for operational status="retired" for two rows in the Excel,on those two rows one row has the child record as "retired" and other doesn't have.
so when the update operation takes place it updates even for the record which doesn't have the child record as retired.
for example:
if i have two records, in which the first records child operational status=retired and the second record child operational status="operational", and when i update the parent(cmdb_ci_appl) first and second record with operational status="retired" it updates for both the records.
even for the one which doesn't have the child record as "retired".
gs.log satisfies every condition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 07:00 AM
I need you to check few things for me.
1. If you look at the u_cmdb_data table, what's the column name of the 'Operational Status' field. Is it u_operational_status?
2. What do the QUERY messages contain? Go to System Logs -> System Log -> Script Log Statements and search for message contains QUERY:
You can test this as a background script as well. Grab a name of the parent from your excel and replace <Name> in my script below when running it.
var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('parent.name', '<Name>');
gr.addQuery('child.operational_status', '!=', '6');
gr.query();
gs.log('The parent has ' + gr.getRowCount() + ' childs that are not Retired');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 07:24 AM
even i do have the same problem,
1)cmdb_data it is u_operational_status
2)i have attached the log picture..in that it executes everything
and when i run the background script
for every application name,it gives the same output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2018 07:57 AM
yes the cmdb_data it is u_operational_status
i have attached the log picture..in that it executes everything
if i updates for a particular application it checks for entire child record all the applications.
for example:
i if tries to update first application to retired its checks for all the application child status is "retired".
And the problem is if its find any application with child operational status="retired" it allows the first application to update to "retired" even though the firs application child status is not in "retired"
Note: it works fine if no other application status is in retired other than the one which i am updating
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2018 01:11 AM
"And the problem is if its find any application with child operational status="retired" it allows the first application to update to "retired" even though the firs application child status is not in "retired" "
Could you elaborate this more? In the script we've specified in the query that child's operational status must be something other than 'Retired'. If it doesn't find anything it means that all the child's are retired or don't exist.
If it finds something then there is at least one child that is not retired.
We can see in the log that apache linux den 200 doesn't have any active child's so it can be retired. PS Apache03 has 2, so it must not be retired.
So we should end up with active PS Apache03 and inactive apache linux den 200