How do I configure ServiceNow to add default checkboxes for each MRVs item

SamuelChang
Tera Contributor

I want to add a checkbox for each item, which only one can be selected (the other will gray out).

 

Here is what I have in mind

SamuelChang_0-1718720226411.png

 

If I select the first item, the second checkbox should be gray out vice versa. I've looked everywhere, but couldn't find any solution, if anyone have any guidance or alternatives I would be greatly appreciate it!

1 ACCEPTED SOLUTION

function onLoad() {
	var mrvs = g_service_catalog.parent.getValue('default_user_mrvs'); //internal MRVS name
	if (mrvs.length > 2) { //native UI returns [] for empty MRVS value whichc causes parsing error
		var obj = JSON.parse(mrvs);
		for (var i=0; i<obj.length; i++) { //loop through the existing MRVS rows
			if (obj[i].default_user == 'true') { //mrvs checkbox variable name
				g_form.setReadOnly('default_user', true);
			}
		}
	}
	if (g_form.getValue('default_user') == 'true') {
		g_form.setReadOnly('default_user', false);
	}
}

View solution in original post

8 REPLIES 8

Brad Bowman
Kilo Patron
Kilo Patron

Hi Samuel,

This onLoad Catalog Client Script that applies to the MRVS, not the Catalog Item, will do that when adding or editing a row:

function onLoad() {
	var mrvs = g_service_catalog.parent.getValue('default_user_mrvs'); //internal MRVS name
	if (mrvs.length > 2) { //native UI returns [] for empty MRVS value whichc causes parsing error
		var obj = JSON.parse(mrvs);
		for (var i=0; i<obj.length; i++) { //loop through the existing MRVS rows
			if (obj[i].default_user == 'true') { //mrvs checkbox variable name
				g_form.setReadOnly('default_user', true);
			}
		}
	}
}

 

Brad,

Thank you for your quick response tried it on my PDI, but it did not work like I really intended. I added the first two unchecked, the third one checked.

SamuelChang_0-1718724055300.png

When I added the new row the default box still available for me to select, but if I select it then it will set to read-only, and still added as default. So now I have 2 default users (which isn't the goal)

SamuelChang_1-1718724173594.png

Maybe there is something wrong with the logic?

It sounds like maybe you are running the script onChange instead of onLoad, or maybe you have an old script or UI policy in place from a previous attempt?  When I execute your test steps, adding the new (4th) row opens the Add Row dialog with the Default checkbox read-only/grayed out.

BradBowman_0-1718738498252.png

 

Arghhh I see, but I can't reverse it aka edit the default and uncheck the checkbox since it's read-only