how to validate multirow variable date filed

Brahmi Pandla
Tera Guru

Hi Everyone
I have multirow variable date filed, how to validate  date filed with date value 
as shown below first user enter 25/07/25 then second time they enter 23/07/25
my requirement is it should not allow previous date 

BrahmiPandla_1-1750271011921.png

 

 

3 REPLIES 3

larralapid
Kilo Guru

To validate a Date field inside a Multi-Row Variable Set (MRVS) in a catalog item, you’ll need to use Catalog Client Scripts in combination with g_form.getControl() and a loop over the MRVS rows.

 

1. Use a Catalog Client Script (onLoad or onSubmit)

 

Here’s how you can loop through rows and validate a date field:

function onSubmit() {
  var isValid = true;

  var rows = g_form.getMultipleRows(); // all rows of MRVS
  for (var i = 0; i < rows.length; i++) {
    var dateVal = rows[i].variable_name; // replace with your date field's variable name

    if (new Date(dateVal) < new Date()) {
      isValid = false;
      g_form.showFieldMsg('multi_row_variable_set', 'Date must be in the future', 'error');
      break;
    }
  }

  return isValid;
}

 


2.

Alternative: Use g_form.getValue() on MRVS Scoped Name

If the MRVS is named my_mrvs, and your date variable is my_date, access like:

var allRows = g_form.getValue('my_mrvs');

…but this returns a stringified object. You’ll need to parse the value if accessed this way — not recommended unless you’re comfortable with serialized MRVS data.

 


 

🔒 Important:

 

  • MRVS fields are tricky — client scripts must be global (Type: Catalog Client Script) and set for “Applies on Requested Item”.

  • Server-side validation can also be done via Catalog Item Validator Script for extra enforcement.

Animesh_Galande
Tera Contributor

Try adding Catalog Client script applies to Variable Set. 

Animesh_Galande_0-1750328036315.png

Let me know if you need the code for validation.


Ankur Bawiskar
Tera Patron
Tera Patron

@Brahmi Pandla 

previous means which one? the 1st row?

you can use onSubmit catalog client script which applies on catalog item
Then get the MRVS JSON, iterate and then compare the dates and if any date is previous than date in 1st row then throw error.

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