Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Update field outside variable set when row is deleted in MRVS

Ruchi Kumari1
Tera Expert

I am working on a script where i need to update a list collector field when a row is deleted in MRVS.
My catalog is defined in following format:
1. List collector field (outside any variable set) > This allows to select multiple users
2. MRVS with 3 variables defined : reqFor, assetname, serialnumber;

When user is selected, MRVS adds row with details (reqFor, assetname, serialnumber) of selected user. If user is removed, MRVS is getting updated. //working

If I remove a row from MRVS, list collector should be updated. Basically, if i remove any row, user removed from MRVS should also be removed from list field. That is both list collector and MRVS should be in sync. //This is not working.
*I want this onchange to execute only when row is removed*

The resources available in community talks about script in widget but I need that in my client script. To start with, I am trying an onchange client script in MRVS with field value of reqFor. But, I am not getting the alert itself.
any suggestion on how i can achieve this. ?

var requestedFor = g_form.getValue('list_the_existing_machine_name');// MRVS internal name
var parser = JSON.parse(requestedFor);
alert(parser.length);//NO ALERT

/*var valueToRemove ='';
var userListCollector = parent.g_form.getValue('my_list_collector');
var listArr = userListCollector.split(',');
var index = listArr.indexOf(valueToRemove);
if(index! == -1){
listArr.splice(index,1);
parent.g_form.setValue(userListCollector, listArr.join(','));*/

 

Does onchange script work at all when row is removed ? I tried giving a simple alert on change of variable in MRVs and i did not get that alert as well.

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Ruchi Kumari1 

You cannot easily determine using client script etc on MRVS whether row was added/removed.

you can determine if row is added or removed using this workaround and then accordingly modify the outside list collector variable

MRVS detect when a row is removed or deleted 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Ruchi Kumari1 

You cannot easily determine using client script etc on MRVS whether row was added/removed.

you can determine if row is added or removed using this workaround and then accordingly modify the outside list collector variable

MRVS detect when a row is removed or deleted 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader