Defined Related List from multiple tables

pdom
Mega Expert

Hello,

I have the following setup

On Request Item, I have a field called "Completed by change"

On Incident Table, I have a field called "Caused by Change"

On Problem Table, I have two fields called "Resolved by change" and "Caused by change"

Now I have two create Two related lists called "Items Caused by Change" and "Items Resolved by Change" and show up the above tasks

I am not sure how to created a related list from multiple table, like the "Items Resolved by Change" on change table should show up the Request item and the Problem records that are related to the change under this related list

Any help please:(

7 REPLIES 7

pdom
Mega Expert

Well Figured out the correct answer. I have tested on my dev instance, therefore the reference field names are different from question, On Incident it is Caused_by, and on problem it is 'rfc' which are referring to the change record



I have used arrays in Relationships



Created a relationship where,



Advanced = true



Applies To -- answer = 'change_request';


Query From -- answer = 'task';



Query With



(function refineQuery(current, parent) {


var mergedArray = new ArrayUtil();
var problemArray = [];
var incidentArray = [];


var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('caused_by', parent.sys_id);
incidentGR.query();


while(incidentGR.next()) {
      incidentArray.push(incidentGR.getValue('sys_id'));
}



/*
Do the same as above for probelm
*/

var problemGR = new GlideRecord('problem');
problemGR.addQuery('rfc', parent.sys_id);
problemGR.query();


while(problemGR.next()) {
      problemArray.push(problemGR.getValue('sys_id'));
}



// Make a union of all arrays
mergedArray = mergedArray.concat(problemArray, incidentArray);


current.addQuery('sys_id', 'IN', mergedArray);



})(current, parent);


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Can you close the thread then by marking it Answered?



Regards,


I think I have started this thread as discussion. No option to mark it as Answered