Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Set alert message if the column fields are empty in multirow variable set

Jay N
Tera Contributor

Hi Experts,

 

We have a requirement to alert user when he submits the catalog form with empty values in multirow variable set.

JayN_0-1665479986741.pngJayN_1-1665480022919.png

 

Thanks, Jay

4 REPLIES 4

Muhammad Khan
Mega Sage

Wouldn't it be better to make those variables/columns mandatory?

Hi Muhammad,

 

Thanks for quick response.

As per the requirement we have autopopulated 5 rows with one column value filled-in, other 2 columns are mandatory fields. Here even without filling the data in other 2 columns, we are able submit the form, we need to restrict sending the data with empty fields.

Well, you might have to create onSubmit() Catalog Client Script which will check/validate for empty values. Something like below should work.

function onSubmit(){

        var mrvsValueStr = g_form.getValue('<backend_name_of_mrvs_variable>');
        var mrvs = JSON.parse(mrvsValueStr);

        for(var i=0; i<mrvs.length; i++){
                if(mrvs[i].<backend_name_of_role_owner_variable> == "" || mrvs[i].<backend_name_of_role_approvers_variable> == ""){
                        g_form.addErrorMessage('Some columns are missing in mrvs rows');
                        return false;
                }
        }
}

 

Also refer to below KB article.

Setting a multi-row variable mandatory 

Manny11
Tera Expert

I understand this is an old post, but how about creating a hidden boolean  is true , then  auto sets to false when any mandatory variables are not empty.

This way one can configure based off the hidden variable.