On Change Client Script to hide options ...

Zod
Giga Guru

Hi,

I need to remove options for a field - incase the field was changed to a certain value (NOT SUBMITTED).

Usually I would think an on change client script should do the job ... something like:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

  if (isLoading || newValue === '') {

  return;

  }

  if (g_form.getValue('abc_status' == '900')) {

  g_form.removeOption('abc_status', 100);

  g_form.removeOption('abc_status', 200);

  }

  }

It doesn't work ... could anyone please tell me why?!

1 ACCEPTED SOLUTION

Gurpreet07
Mega Sage

condition should be


if (g_form.getValue('abc_status') == '900') {


View solution in original post

7 REPLIES 7

Zod
Giga Guru

sorry .. missed the ' ' ... anyhow not working ...



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue === '') {


  return;


  }


  if (g_form.getValue('abc_status' == '900')) {


  g_form.removeOption('abc_status', '100');


  g_form.removeOption('abc_status', '200');


  }


  }


amlanpal
Kilo Sage

Hi,



Please use the below script, and give it a try:



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue === '') {


  return;


  }


  if (g_form.getValue('abc_status' == '900')) {


  g_form.removeOption('abc_status', '100');


  g_form.removeOption('abc_status', '200');


  }


  }



I hope this helps.Please mark correct/helpful based on impact


Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Have you made a log to see that it goes into the if statement?


gs.log not allowed within client script ... . How to add log?


Sorry - I'm a low-code bro 😉