MRVS

kali
Tera Contributor

Hi All,

I have created a variable set inside the catalog item and i want to run a catalog client script on the catalog item when the MRVS value is added by the end user.I have used the onsubmit catalog client script in the variable set but in the g_form.getValue('mrvs_name').I am not getting any value, is there any other way to do this?

5 REPLIES 5

Tanushree Maiti
Tera Patron

Hi @kali 

 

Use an onSubmit Script on the Main Catalog Item :If you want to validate or process the MRVS data right before the entire form is submitted, you must place the Catalog Client Script on the Catalog Item itself, not inside the variable set.

  • Create a new Catalog Client Script.
  • Set Applies to to A Catalog Item.
  • Set Type to onSubmit.
  • Use the MRVS Internal Name

Sample code//update as per your requirement

 

function onSubmit() {

    var mrvsData = g_form.getValue('your_mrvs_internal_name');

    if (mrvsData && mrvsData != '[]') {

        var parser = JSON.parse(mrvsData);

        for (var i = 0; i < parser.length; i++) {

          var specificVariableValue = parser[i].internal_variable_name;

           if (specificVariableValue == 'some_condition') {

                g_form.addErrorMessage('Your validation message.');

                return false; // Aborts submission if validation fails

            }

        }

    }

}

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti