Issue with g_form.getValue()

Hritik
Tera Expert

Evening All,

 

I have a below onChange client script which throws an unexpected error on the form:

Client Script:

 

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
   
   if(g_form.getValue('requested_environment_access' == "3d"))
   alert('hey buddy');
   
      return;
   }

   //Type appropriate comment here, and begin script below
   
}

 

 

 

Error:

Hritik_0-1677506854152.png

 

Could you please help me here?

 

Thanks in Advance,

Hritik

1 ACCEPTED SOLUTION

Hi @Hritik 

 

please check if the 'UI Type' field in client script is selected as All are not. Also, check if the 'variable name' field is selected correctly or not.

 

priyasunku_0-1677515686794.png

In the variable configuration have you included None if not 3d will be selected all the time and you will get the alert.

 

priyasunku_1-1677515747077.png

I am asking to check above mentioned because the script you have written is correct the mistake is somewhere else.

 

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

 

 

View solution in original post

10 REPLIES 10

Hi 

 

you need validate with the choice value not the label.

 

g_form.getValue(<field_name>) == 'choice value'

 

Thanks.

Hi Faizel,

 

Thanks for the response. 

 

I am validating it with choice value only, still not working ☹️

Hi @Hritik 

 

please check if the 'UI Type' field in client script is selected as All are not. Also, check if the 'variable name' field is selected correctly or not.

 

priyasunku_0-1677515686794.png

In the variable configuration have you included None if not 3d will be selected all the time and you will get the alert.

 

priyasunku_1-1677515747077.png

I am asking to check above mentioned because the script you have written is correct the mistake is somewhere else.

 

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

 

 

@Hritik 

Glad to know that my script helped in removing the error.

Now coming to your question

Are you comparing the correct value?

what type of field it is?

Can you share field configuration screenshot of dictionary?

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

Hi Ankur,

 

PFB: 

Client Script: 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {   
   }
	return;
   }
  
  if(g_form.getValue('requested_environment_access') == "3d")
   { 
    alert("test");
}
}

 

Variable configuration:

Hritik_0-1677510344217.pngHritik_1-1677510364745.png