
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2017 07:58 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2017 12:17 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2017 02:00 PM
So you actually want to populate a list-type field based on a selection from another list-type field?
If you don't need multiple choice in the Annu field, I suggest to turn it into a reference or choice field.
In the below example, I am using a category field, which is a choice list field, to choose a value from.
Then, in the list field, called "drop" (u_drop), I expect values to show up. The values are from another table (called my_table), which the category field appears on.
My "drop" field (your Ayesha) has the advanced reference qualifier similar to what I gave you earlier.
Try this:
Type: onChange --> of the category field (similar to your Annu)
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var category = g_form.getValue('category').toString();
var list = category;
var array = list.split(',');
for(var i=0; i<array.length;i++) {
var stnd = new GlideRecord('u_my_table');
stnd.addQuery('u_category', array[i]); //category field on my_table
stnd.query();
stnd.query(getMeTheNames); //using a callback function
}
}
function getMeTheNames(stnd) {
var list = new Array();
while (stnd.next()) {
list.push(stnd.sys_id);
}
g_form.setValue('u_drop', list);
}
Let me know if that helps.
harel
Please mark as correct or helpful based on impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2017 02:33 PM
Harel,
Just have couple of doubts
1. Is your reference qualifier syntax is right ? : javascript:'u_annu='+current.u _annu;
2. My both fields are the from the same table & as per client request Annu type should be List only. Still i can try with your code ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2017 02:57 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2017 07:24 AM
I am probably a bit confused and not clear on your setup then.
So you have Service Offering table that has records in it. Each record has a service type - Product or Application and a parent. The parent will show in Annu and the its child records will show in Ayesha. Correct?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2017 08:06 AM
Harel,
You are correct. Service Offering table has a Service type choice field which consist of - Product or Application.
Whenever i select any Parent table example: ITSM is a Parent record which has a Child records as Incident, Change & Problem, Parent record i.e ITSM should falls in Annu & child recrods i.e Incident, Problem, Change must fall in Ayesha table.