How to know which row in Multirow variable set is edited

asifnoor
Kilo Patron

Hi,

I have a multirow variable set on a catalog item. In the catalog item, once you select a specific Network value in a variable , i fetch the associated data and displaying them in multirow variable set.

So for 1 specific network, there can be rows anywhere between 5 to 20. In each row, we have 10 fields.

If user has edited 2 rows in these 20 rows, is there an easier way to find out which of the 2 rows are edited?

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Unfortunately there is no OOB Way solution for this.

So here is how i did it.

Create a variable (yes/no) field in a variable set.

Make this variable hidden on add/edit.

Whenever a row is edited, i have updated the edited value to yes.

Then in my workflow on task table, i have fetched all the variables and removed the entries which are not edited. Below is the code snippet that i have used to update the RITM with only the entries that are edited.

mrvs = current.variables.my_varset;
var rowCount = mrvs.getRowCount();
for(k=0;k<rowCount;k++) {
  var row = mrvs.getRow(k);
  if(row.edit_row!= "Yes") {
    row.deleteRow();
    rowCount = mrvs.getRowCount();
    //reinitialize the counter variable so that it checks again from beginning as the multirow variable set and rowcount gets updated on delete.
    k=-1; 
  }
}
//once all non edited rows are removed, update the multivarset bck to the record.
current.variables.my_varset= mrvs;

 

View solution in original post

12 REPLIES 12

Hi,

Thanks for your response.

Let say you have a catalog item in which there is a multirow variable set of 25 rows.

Now user edit 2 rows in that.. and submit. A new request gets created and RITM shows all 25 rows in it.

Instead of showing all 25, I wanted to show only the 2 that are edited.

So as of now, I have added a field Edited (yes/no) and when edited making that as yes. Now trying to remove all other 23 rows from that RITM.

I don't think there is a OOB way do this.

 

you can enhance the your solution like below

1.Hide the yes/no flag field using UI policy in variable set.

2. Create an onchange client script in your MRV field on which user will update values

3.on the onchange script  call script include to manipulate the mrv object  to set the flag to true on a specific row

 

whenever user changes  field in particular row , use the newValue object to identify the particular row in which the change was applied, then set the  flag for that row.

 

 

Check below links for more details:

 

https://community.servicenow.com/community?id=community_blog&sys_id=865b5aeddbc023c0feb1a851ca9619f9

https://community.servicenow.com/community?id=community_article&sys_id=2a508caedbf47f48d82ffb243996198f

 

 

 

 

 

 

 

asifnoor
Kilo Patron

Unfortunately there is no OOB Way solution for this.

So here is how i did it.

Create a variable (yes/no) field in a variable set.

Make this variable hidden on add/edit.

Whenever a row is edited, i have updated the edited value to yes.

Then in my workflow on task table, i have fetched all the variables and removed the entries which are not edited. Below is the code snippet that i have used to update the RITM with only the entries that are edited.

mrvs = current.variables.my_varset;
var rowCount = mrvs.getRowCount();
for(k=0;k<rowCount;k++) {
  var row = mrvs.getRow(k);
  if(row.edit_row!= "Yes") {
    row.deleteRow();
    rowCount = mrvs.getRowCount();
    //reinitialize the counter variable so that it checks again from beginning as the multirow variable set and rowcount gets updated on delete.
    k=-1; 
  }
}
//once all non edited rows are removed, update the multivarset bck to the record.
current.variables.my_varset= mrvs;

 

JohnG4
Kilo Contributor

How did you hide the hidden field in the columns? i can hide the field in the modal via onload.

create a ui policy and make the variable hide. Mark the comment as helpful if it helps.