How to make cient script for empty mutli row vairbale

aggarwaltan
Tera Contributor

aggarwaltan_0-1744525440451.png

These details in the form are necssary so when I  make the filed Firewall details empty it should not generate any REq or it should not generated it's task number then . 

Whenerver we click on Add button  this kind of form is appears :- 

aggarwaltan_2-1744525555059.png

when I make it as a empty in actual it should not generate any REQor TASK but in my client it's generating  REQ weather it is filled or not  

 

So here is my client script code :- 

function onSubmit() {
   //Type appropriate comment here, and begin script below
    var firewallDetails = g_form.getValue('firewall_details');
   
   //console.log("firewallDetails: " + firewallDetails);
   
     if (!firewallDetails || firewallDetails === '[]') {
         g_form.addErrorMessage("Please add at least one row to the multi-row variable set.");
         return false; // This prevents submission
     }

     return true;
    // try {
    //     var rows = JSON.parse(firewallDetails);
    //     if (!rows || rows.length === 0) {
    //         g_form.addErrorMessage("Please add at least one row to the multi-row variable set.");
    //         return false;
    //     }
    // } catch (e) {
    //     g_form.addErrorMessage("Invalid input in firewall details.");
    //     return false;
    // }

   
}
 
aggarwaltan_3-1744525647567.png

 

 

 

Please provide the suggestion on this ?

2 REPLIES 2

Vishal Jaswal
Giga Sage

Hello @aggarwaltan 

function onSubmit() {
   var firewallDetails = g_form.getValue('firewall_details');
   if (!firewallDetails || firewallDetails === '[]') {
       g_form.addErrorMessage("Please add at least one row to the multi-row variable set.");
       return false;
   }
   try {
       var rows = JSON.parse(firewallDetails);
       if (!rows || rows.length === 0) {
           g_form.addErrorMessage("Please add at least one row to the multi-row variable set.");
           return false;
       }
   } catch (e) {
       g_form.addErrorMessage("Error reading firewall details. Please ensure it's filled in properly.");
       return false;
   }
   return true;
}

Hope that helps!

Ankur Bawiskar
Tera Patron
Tera Patron

@aggarwaltan 

Simply make the MRVS mandatory so that it ensures at least 1 row is present

with this no scripting required

You can just make a Catalog UI Policy (on the Catalog Item) with a Catalog UI Policy Action to make the MRVS mandatory. In the UI Policy Action you can just select the MRVS.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader