URGENT * Client script on Change not working on variable set in Catalog Item

JérômeM
Tera Contributor

Hello Community! 
I have an urgent issue that I need to solve. 
I created the following client script at catalog item level and it works fine. 
However, my users are in the need to add multiple rows, so I created a variable set and included the script in there, but it doesn't work anymore. 
Any idea why an onChange value doesn't work in variable set ? Should I do it differently ? 
See my code : 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   // Clear any previous messages
   g_form.hideFieldMsg('line_number_2');

   var lineNumber = g_form.getValue('line_number_2');

   if (lineNumber.indexOf('/OOB') > -1 ) {
      g_form.showFieldMsg('line_number_2', "This line is of type Out of Band", 'info', false);
   } else if (lineNumber.indexOf('/B') > -1 ) {
      g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 100 Mbits/S", 'info', false);
   } else if (lineNumber.indexOf('/C') > -1 ) {
      g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 1.000 Mbits/S", 'info', false);
   } else if (lineNumber.indexOf('/D') > -1 ) {
      g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 10.000 Mbits/S", 'info', false);
   } else if (lineNumber.indexOf('/E') > -1 ) {
      g_form.showFieldMsg('line_number_2', "This line is of type Dark Fiber", 'info', false);
   } else if (lineNumber.indexOf('/F') > -1 ) {
      g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 200 Mbits/S", 'info', false);
   } else if (lineNumber.indexOf('/G') > -1 ) {
      g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 500 Mbits/S", 'info', false);
   } else if (lineNumber.indexOf('/H') > -1 ) {
      g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 2.000 Mbits/S", 'info', false);
   } else {
      g_form.showFieldMsg('line_number_2', 'Type of the line is not specified yet', 'info', false);
   }
}


Thanks 
Jérôme

1 ACCEPTED SOLUTION

@JérômeM 

nope, I am referring create a fresh variable within that MRVS and deactivate the line_number_2

Then create fresh client script on that new variable and then see

Did the alert come?

Remember the onChange will run only when you type the details in variable and you click elsewhere on that modal, it won't trigger as and when you type.

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

View solution in original post

9 REPLIES 9

Arun_Manoj
Mega Sage

Hi @JérômeM ,

 

Note the use of g_sc_form instead of g_form.

You need to use client scripts within the MRVS itself using a Catalog Client Script scoped to the MRVS, and use the g_sc_form API (not g_form).

 

If the solution is Helpful.Please give healpful.

 

Thanks

Arun

Hello Arun 
I tried g_sc_form but it doesn't work. 
Best regards
Jérôme

Ankur Bawiskar
Tera Patron
Tera Patron

@JérômeM 

please share onChange is running on which variable set and which variable?

line_number_2 variable is within MRVS or outside?

share some screenshots

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

Hey @Ankur Bawiskar 
See screenshots attached. The script runs on the variable set and the correct variable. 🙂