Unique requirement - Can we sort rows in an MRVS in ServiceNow?

dharam743
Tera Contributor

Can we sort rows in an MRVS in ServiceNow?

For example, if the serial number is the first column, how can we ensure that every time we add a new row, it is assigned the next serial number rather than simply being added at the end of the list?

Also, if I have already entered 20 rows and need to insert a new row in the middle of the list, is this possible? 

 

MRVS.png

 

If we want to add new record at serial number 2, earlier record at serial no. 2 should become 3, 3 --> 4 and so on.
instead adding it to last position.

 

 

Add.png

 

 

MRSV2.png


 

 

 

2 REPLIES 2

Ahmmed Ali
Mega Sage

Hello @dharam743 

 

This can be done. You will need to create a widget and add it in the catalog item with custom type variable. Now in the widget, you can add event listener function which will trigger on the field change and in function check if the field name is same as your MRVS variable set name. If yes, then read the MRVS value and you can manipulate the data to have it sorted based on the serial number. then populate the sorted data in MRVS.

 

Example script for event listener:

AhmmedAli_0-1736089670584.png

reference: https://www.servicenow.com/community/developer-forum/widget-that-reacts-to-onchange-event-of-variabl... 

 

Note: 

The script would be little complex and also you need to make sure that infinite loop does not happen as the widget reacts to MRVS change and again changes the MRVS value which will intern again change trigger the same script.

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Ankur Bawiskar
Tera Patron
Tera Patron

@dharam743 

this is possible. Determine if a new row is added or removed and then determine the next serial number or adjust if a row is removed

check this link on how to determine if row is added/removed and you can enhance the logic as per your requirement

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