Make variable mandatory on MVRS onsubmit

Ash41
Kilo Sage

Hi Team, 

 

I was trying below code to restriction submission of request before filling in mandatory variable not working, please suggest

function onSubmit() { 
    var values = g_form.getValue('service_details'); // give here mrvs variable name
    var parser = JSON.parse(values);
    for (var i = 0; i < parser.length; i++) {
 
        var service = parser[i].service_question; // give here the variable name for proportion
		var serviceAnswer =parser[i].service_question_answer;
		alert(serviceAnswer);
		alert(service);
        if (service != "" && serviceAnswer =='') {
 
            g_form.addErrorMessage('please fill Service Answer');
 
            return false;
 
        }
}
}

 

8 REPLIES 8

Nayan  Dhamane
Kilo Sage
Kilo Sage

Hello @Ash41 ,

Please try UI policy to make fields mandatory on form which is the standard practice.

You can also select the variables from MRVS in the ui Policy action.

 

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Hi Nayan, 

 

I have already applied UI policy to make variable mandatory, still form is getting submitted if variable is empty

 

Ok not sure why that is happening is * visible on field on required condition. 

Going for the script can you please let me know are you getting values in the alerts which you have added.

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Hi Nayan, 

 

Yes, I'm able to see * on variable. which is from Ui policy. 

From script, when I put alerts for below getting undefined.

alert(serviceAnswer);