- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2016 06:51 AM
Hi All,
I want to query the child value based on parent value in table cmdb_rel_ci
How can this be done
Thanks,
Abhi
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2016 12:20 PM
Thanks. I didn't see that you changed the childList.push() line. You cannot dot-walk inside a getValue() call. IN your case, use this.
childList.push(rel.child.name);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2016 09:22 AM
Thank you. if row count is 0, then it means one of two things. Either the parent ID is not being sent properly from the client to the server (which it appears to be from the script unless the field name is wrong somewhere) or there really are no relationships for the sample you have chosen. Another debug statement or two should determine if it is the first case. Checking the actual data on the cmdb_rel_ci table can check the second.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2016 11:57 AM
with this below script include
helloman : function(){
var parentId = this.getParameter('sysparm_business_service');
var childList = [];
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('parent.name','=', parentId);
// parent.name=Bond Trading
rel.query();
while (rel.next()) {
childList.push(rel.getValue('child.name'));
}
return childList.join(',');
}
I am able to get the correct Row count as per cmdb_rel_ci .. but not able to get the child value

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2016 12:06 PM
Rather than passing the business service name, try passing the sys_id.
From the client script use
var ab_data = g_form.getValue('business_service');
and then in your script include query for it with
rel.addQuery('parent', parentId);
Much safer to use sys_ids than display values when doing queries. Verify you have a sys_id in the script include. If so, report how many rows are counted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2016 12:15 PM
its return 8 rows which is what it is in the relationship table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2016 12:16 PM
just thr value of the child seems to be blank rest all looks good
var HelloMan = Class.create();
HelloMan.prototype = Object.extendsObject(AbstractAjaxProcessor, {
helloman : function(){
var parentId = this.getParameter('sysparm_business_service');
var childList = [];
var rel = new GlideRecord('cmdb_rel_ci');
// rel.addQuery('parent.name','=', parentId);
rel.addQuery('parent', parentId);
rel.query();
while (rel.next()) {
childList.push(rel.getValue('child.name'));
}
return childList.join(",");
}
});