List Collector records to display in related list

poojayadav
Tera Contributor

Requirement: When selections are made in a variable of type: List collector on the catalog form, display selected records on the RITM & TASK form under related list.

2 REPLIES 2

dvp
Mega Sage
Mega Sage

Hello Pooja,



First you need to create a relationship between tables, it can be either many to many(m2m) or 1 to many. Once you have the relationship in place, the system automatically creates a related list.



Identify the field that is relating the RITM and List collector table that is defined in relationship and insert records by using a sample script something like below if the relationship is m2m




var ci = current.variables.LIST_COLLECTOR_VARIABLE_NAME;



var arr = ci.split(',');



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


{


var gr = new GlideRecord('task_ci');  


gr.initialize();


gr.task = current.sys_id


gr.ci_item = arr[i]


gr.insert();



}


Brad Tilton
ServiceNow Employee
ServiceNow Employee

The approach that dvp suggested will work, but another option might be to create a custom relationship so you don't have to create records on a table for every ritm. It may be a bit more complex since your list collector is a variable rather than form field, but you might want to check it out.