Make Mandatory a field out side of multi row variable set on the catalog item based on MRVS variable

srikriti
Tera Contributor

Hi All,

 

I have a requirement I need to make a field mandatory which is outside of multi row variable set on the basis of field in the multirow variable set

test1 = field inside MRVS

test = field outside MRVS

test1 is not empty need to make test field mandatory 

below ui policy i have tried no luck can anyone guide me how to proceed 

srikriti_0-1688638443464.png

 

srikriti_1-1688638474596.png

 

 

Thanks

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

I don't think you can do this with a UI Policy.  A Catalog Client Script like this within the MRVS will check the variable on the row you are about to add, as well as each of the previously-added rows.  If any of the rows have the variable populated, it will make a variable outside of the MRVS mandatory.

function onSubmit() {
	var populated = 'false';
	if (g_form.getValue('test1') != '') { //MRVS variable name
		populated = 'true';
	} else {
		var mrvs = g_service_catalog.parent.getValue('mrvs'); //internal name of MRVS
		if(mrvs.length > 2){//native UI returns [] for empty MRVS value which causes a parsing error
			var obj = JSON.parse(mrvs);
			for (var i = 0; i < obj.length; i++) {
				if (obj[i].test1 != '') {
					populated = 'true';
				}
			}
		}
	}
	if (populated == 'true') {
		parent.g_form.setMandatory('test', true);
	} else {
		parent.g_form.setMandatory('test', false);
	}
}

If you are using Service Portal or Employee Center, there's another step required to access the parent.g_form.  You'll need a Catalog Client Script like this on the Catalog Item, not within the MRVS:

function onLoad() {
	if (this) { // only needed for Service Portal
		// make the g_form object for the parent item available from the MRVS window
		this.cat_g_form = g_form;
	}
}

then the end of the MRVS onSubmit script would look like this to set the variable as mandatory in either the native UI or SP/EC:

if (populated == 'true') {		
    if (this) { //Service Portal method
		this.cat_g_form.setMandatory('test', true);
    } else { //native UI method
		parent.g_form.setMandatory('test', true);
} else {
    if (this) { //Service Portal method
		this.cat_g_form.setMandatory('test', fasle);
    } else { //native UI method
		parent.g_form.setMandatory('test', false);
}