The CreatorCon Call for Content is officially open! Get started here.

how to query cmdb_rel_ci table to get parent and child value using glide record

Abhinab Achary1
Tera Guru

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

1 ACCEPTED SOLUTION

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);


View solution in original post

24 REPLIES 24

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.


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


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.


its return 8 rows which is what it is in the relationship table


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(",");


  }




});