Removing the mapped option in 2 List collector variables based on selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 08:36 PM
Hi All,
I have a requirement as mentioned below.
In catalog item I have 2 list collector variables.
1- 1st variables reflect the task number and we can select multiple tasks ex : INC,PRB,CHG,TASK since its a list collector variable
2- 2nd list collector variables reflects the corresponding selected tasks response and resolution SLA details.
Ex in list collector 1 i selected the tasks as INC00001, TASK00002, PRB 123456, CHG 23451.
Now corresponding to above selected tasks in the list collector 2 i have the option to choose response/resolution SLA's for INC00001 (RESPSLA1, RESOSLA2), TASK00002(RESPSLA3, RESOSLA4), PRB 123456(RESPSLA5, RESOSLA6), CHG 23451(RESPSLA7, RESOSLA8)
Hence in the list collector 2 i have 8 values with 2 SLA values each mapped to selected Tasks.
Now if I remove INC00001 from list collector 1 then RESPSLA1, RESOSLA2 should get removed from list collector 2.
if I remove TASK00002 from list collector 1 then RESPSLA3, RESOSLA4 should get removed from list collector 2.
Let me know as how this requirement can be achieved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 11:03 PM
Thanks @Ankur Bawiskar - Any reference or skeleton code that you can share for my reference please on top of which I can build the rest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 11:30 PM
I already shared the approach. Anyone with average development skills can achieve the requirement.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 08:07 PM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 09:45 PM - edited 09-21-2023 09:47 PM
Dear Arpitnigam,
@arpitnigam , hope you're doing great!
Give this a shot!
- Create a client script and attach it to the second list collector variable.
- In the client script, add the following code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
// Get the values of the first list collector variable.
var taskList = g_form.getValue('list_collector_variable_1');
// Get the values of the second list collector variable.
var responseResolutionSLAList = g_form.getValue('list_collector_variable_2');
// Create a new array to store the filtered response/resolution SLA values.
var filteredResponseResolutionSLAList = [];
// Iterate over the response/resolution SLA values and add them to the filtered array if the corresponding task is selected in the first list collector variable.
for (var i = 0; i < responseResolutionSLAList.length; i++) {
var responseResolutionSLA = responseResolutionSLAList[i];
var task = responseResolutionSLA.split('-')[0];
if (taskList.includes(task)) {
filteredResponseResolutionSLAList.push(responseResolutionSLA);
}
}
// Set the values of the second list collector variable to the filtered array.
g_form.setValue('list_collector_variable_2', filteredResponseResolutionSLAList);
}
NOTE:
These are the below criteria, that was followed on the above script!
EXAMPLE 1:
@arpitnigam , If you select the tasks INC00001 and TASK00002 in the first list collector variable, the second list collector variable will contain the following values:
- RESPSLA1
- RESOSLA2
- RESPSLA3
- RESOSLA4
EXAMPLE 2:
@arpitnigam , If you then deselects the task INC00001 from the first list collector variable, the second list collector variable will be filtered and the following values will be removed:
- RESPSLA1
- RESOSLA2
The remaining values in the second list collector variable will be RESPSLA3 and RESOSLA4.
Kindly, please mark my solution as Helpful/Correct, if applicable. If I could help you with your Query then, please hit the Thumb Icon and mark as Correct!!
Thanks & Regards,
Revanth. K
Product Test Automation Engineer