Variable option from MRVS should make a variable on the form mandatory

Community Alums
Not applicable

Hi,

I have a variable Record Type in MRVS which is a selectbox. When we select an option (Other) in this variable, it should make a variable (Add Attachment) on the form mandatory. Is it possible? If yes, how is it done? Kindly help.

 

other.png

 

attach.png

 

Regards

Suman P.

6 REPLIES 6

Anubhav24
Mega Sage
Mega Sage

Hi @Community Alums ,

The tough part is to get the MRVS data into the form , can you try and see just g_form.getValue('MRVS VARIABLE SET NAME');. This should return you the values in a JSON format post that can you set your field mandatory based on the value. The tricky part is at which event you will write this mandatory check. You can try writing an onSubmit Client Script on your MRVS and then try to set the mandatory check on your form by accessing the MRVS values after collecting it using as stated in the above statement.

To access values and how to process it you can refer below thread:

https://www.servicenow.com/community/itom-forum/how-to-populate-mrvs-variable-values-into-a-catalog-item/td-p/2880903

 

https://www.servicenow.com/community/itsm-articles/scripting-with-a-multi-row-variable-set-and-a-possible-reporting/ta-p/2300082

 

Please mark correct/helpful if my response helped you.

Brad Bowman
Kilo Patron
Kilo Patron

You can do this with an onChange or onSubmit Catalog Client Script that Applies to the MRVS:

function onSubmit() {
	if (g_form.getValue('v_record_type') == 'other') { //MRVS variable name and choice value
		if (this) { //Service Portal method
			this.cat_g_form.setMandatory('v_attachment', true); //catalog item variable name
		} else { //native UI method
			parent.g_form.setMandatory('v_attachment', true); //catalog item variable name
		}
	}
}

If you are using Service Portal, this onLoad Catalog Client Script that applies to the Catalog Item is also required:

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

 

Community Alums
Not applicable

Hi @Brad Bowman ,

 

I have used this, but it is not working. It is directly submitting the form. It is a catalog item.

 

1.png

 

function onSubmit() {

    if (g_form.getValue('record_type') == 'noinfo') //MRVS variable name and choice value
    { 
        g_form.setMandatory('add_attachments', true); //catalog item variable name
    }
}

 

Regards

Suman P.

To use this approach you would have to first get the value of the MRVS, then loop through the results to see if any of the record_type variables have the value of noinfo in any row.  The problem with this approach is that you are only then setting the attachment variable to mandatory, so it's not as user-friendly as giving them the chance to notice that it's already mandatory before submitting the form.