Make variable inside a MRVS mandatory onSubmit

Michael_Nash
Tera Contributor

Hi Guys,

 

I have a requirement on a record producer tom make a variable inside a MRVS mandatory when the customer clicks submit.

 

Is this possible?

4 REPLIES 4

Anirudh Pathak
Mega Sage

@Anirudh Pathak Thanks But I'm looking to make only 1 variable inside that MRVS mandatory.

Service_RNow
Mega Sage

Hi @Michael_Nash 

follow thread it will be helpful

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0622896

 

Mark my answer as accepted solution and helpful if helps you.

 

Maddysunil
Kilo Sage

@Michael_Nash 

I think you can make that particular variable mandatory from the variable itself, and to prevent the form submisstion until it is filled, you can write a on submit client script. Below is the sample script you can use:

 

function onSubmit() {
    var mrvs = g_form.getReference('mrvs_field'); // Replace 'mrvs_field' with the actual field name of your MRVS
    if (mrvs) {
        var rows = mrvs.getRows();
        for (var i = 0; i < rows.length; i++) {
            var row = rows[i];
            var mandatoryFields = row.getMandatoryFields();
            for (var j = 0; j < mandatoryFields.length; j++) {
                var field = mandatoryFields[j];
                if (!row.getValue(field.name)) {
                    alert("Please fill in all mandatory fields.");
                    return false; // Prevent form submission
                }
            }
        }
    }
    return true; // Allow form submission if all mandatory fields are filled
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks