List collector value not removed from script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 12:24 PM
Hi,
I am trying to remove values from list collector through onsubmit client script.
I have a script include which returns what values are to be removed from the list collector on submit. I tried below script but no luck. I am getting the expected alerts. What am i missing ?
var mrvsValues = g_form.getValue('list_the_existing_machine_name');
var mrvsSelectedUsers = [];
var rows = JSON.parse(mrvsValues);
for (var i = 0; i < rows.length; i++) {
var val = rows[i].req_for;
mrvsSelectedUsers.push(val.toString());
}
var userListCollector = g_form.getValue('requested_for');
var listArr = userListCollector.split(',');
alert('listArr ' + listArr); //Getting expected alert
var gaGetUserDetails = new GlideAjax('GetUserDetails');
gaGetUserDetails.addParam('sysparm_name', 'getUserDetails');
gaGetUserDetails.addParam('sysparm_listusers', listArr);
gaGetUserDetails.addParam('sysparm_mrvsusers', mrvsSelectedUsers);
gaGetUserDetails.getXMLAnswer(parseAnswer);
function parseAnswer(response) {
//returned value should be array of sysids of user to be removed from list
var answer = response;
var test = answer.split(',');
alert('anser1 = ' + test); ///getting expected alert
//if (answer.length > 0) {
for (var a = 0; a < test.length; a++) {
var valueToRemove = test[a];
alert('Value to remove ' + valueToRemove);
var index = listArr.indexOf(valueToRemove);
alert('index ' + index); //getting expected index value
if (index !== -1) {
listArr.splice(index, 1); //remove value
}
}
alert('listArr100 ' + listArr); //getting expected value
g_form.setValue('requested_for', listArr.join(','));
return false; //This is false only for testing purpose.
There is no change in the selected values before / after clicking submit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 11:41 PM
Hi @Community Alums , This is an onchange script on list field. I want to update list field on change of values in mrvs.
Since we have a limitation in MRVS (onchange doesnot work in mrvs) I am trying to update the list onsubmit.
I tried with xmlwait as well in my onsubmit, but no luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 11:50 PM
I will recommend not to use onSubmit but please use either of these options and then update the MRVS after RITM is generated
1) workflow run script -> if workflow is used
2) after insert business rule on RITM table
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
‎07-09-2025 11:51 PM
remember these points:
1) Asynchronous GlideAjax won't work as by the time ajax function returns the value your form will get submitted
2) Synchronous GlideAjax is not allowed in portal and scoped application
Refer this link
Refer these links for workaround/solution on how to use Synchronous GlideAjax in onSubmit
How To: Async GlideAjax in an onSubmit script
Asynchronous onSubmit Catalog/Client Scripts in ServiceNow
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
‎07-10-2025 12:04 AM
Hi @Ankur Bawiskar , I cannot add script in workflow/BR to update the list field as the number of RITMS that would be generated is based on the number of users in list.
The expectation is if user/row is removed from MRVS before submit, the list should be also updated with the users so that correct RITMs can be generated.
Because of business requirement, I cannot make the MRVS readonly to restrict user from deleting any row.
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2025 12:08 AM
you can determine if row was added/removed from MRVS and then manipulate the outside variable
check how it can be done using a widget and Variable of type Custom
How to calculate the total of variables into another variable from a multi-row variable set?
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