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

My requirement is based on Service offering selection on change form, I want those values to get checked in the cmdb_rel_ci table on parent column then get the respective child values from relationship table and final;ly display them in the screen.




Client script is



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (isLoading || newValue === '') {


          return;


    }




  var gaj=new GlideAjax('HelloMan');


  gaj.addParam('sysparm_name','helloman');



  var ab_data=g_form.getDisplayBox('business_service').value;


  gaj.addParam('sysparm_business_service',ab_data);


  gaj.getXML(HelloManparse);



  function HelloManparse(response)


  {


  var answer = response.responseXML.documentElement.getAttribute("answer");


// g_form.addInfoMessage(answer);


// alert(answer);



// var list = answer;



  var array = answer.split(",");


    for (var i=0; i < array.length; i++) {


  g_form.addInfoMessage("\nReference value is: " + array[i]);


  }


// g_form.addInfoMessage(answer);



  }




    //Type appropriate comment here, and begin script below


   


}




Server script




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', parentId);


  rel.query();



while (rel.next()) {


        childList.push(rel.getValue('child'));




}


return childList.join(',');


// gs.print(childList);


// return childList;












// var getchild=new GlideRecord('cmdb_rel_ci');



// // return this.getParameter('sysparm_business_service');


// getchild.addQuery('parent',this.getParameter('sysparm_business_service'));


// getchild.query();


// while(getchild.next())


// {


// return getchild.child;


// }







  }




//         type: 'HelloMan';


});


I recommend adding some debug statements to find out:



If the parent ID is being passed correctly and received by the script include.


How many rows are being returned by the rel.query()


What are the contents of the childList array before it gets returned?


What does the client script see in the 'answer' variable after it is parsed?



FWIW, you might want to change your variable name from "array" to "arr" or "list" just to be safe.


if i remove childList.join(',') -> org.mozilla.javascript.NativeArray@f5da90


if returned   childList.join(',') ->   its empty in g_form.addinfomessage


How about the other questions?


rwo count=0;


If the parent ID is being passed correctly and received by the script include. > parent id when passed to client script it return the parent name correctly


child array list contains   after parsed in answer variable> org.mozilla.javascript.NativeArray@1ff8597



childarray contains before sneding to client script as > org.mozilla.javascript.NativeArray@136a76e