How to populate/display Child records with reference to Parent table

AbdulAzeez
Mega Guru

Hello Everyone,

I have 2 list fields 1-Product & 2- Application based on Product(Parent) selection i need to display child records in Application list record. Using Service Offering table as Reference for both the list records

Example

If i select   (IT Service Management)   in Product list then Application list should display all the relevant records like Incident Management, Problem Management, Change Management etc

Please help me out to achieve this

1 ACCEPTED SOLUTION

Hi Abdul,


Try the script below.


A few points to note:


1. I did not use advance reference qual in Annu or in Ayesha, so if you have any, you can remove them.


2. adding more than one parent to Annu field will not update Ayesha with the new records.


3. removing a parent from the Annu field will not remove child records from Ayesha; it can probably be done - I do not know how.


However, adding two parent values to Annu will show the first value's added children in Ayesha. Then, removing the first value from Anu (the one that displays the children) will show in Ayesha the second value's children.


4. both of my fields - Annu and Ayesha - refer to the service offering table. Therefore, the records they show are the display records (name) from the Service Offering table. I do not know of a way to show the parent field display value in Annu, and the child record name in Ayesha when they are both list fields on the same table. If a list field is not a must, we can create a drop down that references the parent from   Service Offering.



Here is the onChange script for Annu:



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


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


  return;


  }



  //Type appropriate comment here, and begin script below


  var annu = g_form.getValue('u_annu');


  var tfm = new GlideRecord('service_offering');


  tfm.addQuery('sys_id', annu);


  tfm.query();


  while(tfm.next()) {


  var list = tfm.parent;


  var array = list.split(',');


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


  var p = new GlideRecord('service_offering');


  p.addQuery('parent', array[i]);


  p.query();


  p.query(getMeTheNames);


  }


  }


}




function getMeTheNames(p) {


  var list = new Array();


  while (p.next()) {


  list.push(p.sys_id);


  }


  g_form.setValue('u_ayesha', list);


}



harel


Please mark as correct or helpful as needed.


View solution in original post

16 REPLIES 16

oharel
Kilo Sage

Not exactly sure of your setup, but it seems that you will need to use advanced reference qualifier.


In the Application List field, Configure Dictionary:


javascript:'product_list='+current.product_list;



You need to change the names of the fields, of-course.


harel


Hello Harel,



Thanks for the respond.



I think you got it right i think am very near but unable to get the appropriate result. Please review my screenshot whats happening.



Capture3.PNG


whenever i click on reference which maps to Service offering table and in which if i select any parent field record say like azeez as shown in below image then azeez child records must be populated in down list field.



Capture4.PNG



Thanks in advance.


Hi Abdul,



Do you mean that when clicking on the magnifying glass and choosing Azeez, the record Azeez does not show up in the field "Annu"?


What's your display field on the Service Offering table?


harel


Harel,



When ever i select azeez under Service offering table i can see it in Annu, know as Azeez is a parent table which consist of child records like abdul, test3, & test4 as shown in above image those records must display in Ayesha list hence vice-versa with abdul(parent field).