Populate List collector into a related list.

Srikanth Menava
Kilo Sage

Hello SNC, 

 I have created a catalog form and it has a list collector variable which is refering to task table and my reference qualifier will filter the items, Everything is fine untill this point.

Now in the RITM created, I want all the selected items from the list collector(which are shown in the variables section) should be populated as individual items in the related list.

Please let me know how this can be achieved.

TIA

1 ACCEPTED SOLUTION

I was able to achieve it myself with the following line in the query of the custom related list,
current.addQuery('sys_id','IN',parent.variables.list_collector_name);

Might be usefull for anyone.

View solution in original post

9 REPLIES 9

No worries, I take no offense 🙂

However, from what I can see on that other thread, there is no mention of the results existing in different tables, which is part of the issue here - you need a single related list to display results from multiple tables, but together, no? (the list collector could grab problem and incident)

If not, this should be a LOT easier -- sorry, I misunderstood when I was suggesting an intermediate custom table to use as a join/view for your related list to use.

In this case, you could definitely set up the relationship as described in the other thread, but you would need a separate related list for each table that has a record type which could be selected with the list collector. You can then write a client script to which looks at each list to see if it is empty and hides it onLoad, if so.

Amit Gujarathi
Giga Sage
Giga Sage

HI @Srikanth Menava ,
I trust you are doing great.

To achieve the desired functionality, you can follow these steps:

  1. Open the RITM (Requested Item) form in ServiceNow's Form Designer.
  2. Identify the related list where you want the selected items to be displayed individually.
  3. Add a new related list field to the form by clicking on the "Related Lists" tab in the Form Designer.
  4. Configure the related list field to display the selected items from the list collector variable.
  5. Use a UI Policy or Client Script to dynamically update the related list field based on the selected items in the list collector variable.

 

function onChangeListCollector() {
  var selectedItems = g_form.getValue('list_collector_variable'); // Get the selected items from the list collector variable
  var relatedList = g_form.getControl('related_list_field'); // Get the related list field control
  
  // Clear the related list field to remove any existing items
  relatedList.removeCurrentValues();

  // Iterate through the selected items and populate them individually in the related list
  for (var i = 0; i < selectedItems.length; i++) {
    var item = selectedItems[i];
    relatedList.addNewItem(item.value); // Add each selected item to the related list
  }
}

// Attach the onChangeListCollector function to the list collector variable
g_form.addOnChange('list_collector_variable', onChangeListCollector);

 


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



AFAIK, you can't add a related list in Form Designer...you can add a "list" variable type to the form...is that what we are talking about here?

@Amit Gujarathi  so as @jMarshal at uLe says As Far As I know(AFAIK) I couldn't add related list in the form designer.

 But I tried something else which gave me a partial result of what I want.

SrikanthMenava_0-1685117321242.png

 

which showed me all the records in task table.

SrikanthMenava_1-1685117321252.png

 

Now All I need is something in the add query line in the relationship.

I was able to achieve it myself with the following line in the query of the custom related list,
current.addQuery('sys_id','IN',parent.variables.list_collector_name);

Might be usefull for anyone.