- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 06:08 AM
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:
Could you please help me here?
Thanks in Advance,
Hritik
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 08:36 AM
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.
In the variable configuration have you included None if not 3d will be selected all the time and you will get the alert.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 06:10 AM
mistake here
you should close the getValue() function and then compare the value
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
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 06:15 AM
Hi Ankur,
I was able to remove the error from the form, but code is still not working.
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
}
The alert inside the function is not triggering.
Could you please help here?
Thanks in Advance,
Hritik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 06:22 AM
Hi,
Do you want to run this script on load? because you have written the script inside the onloading condition.
Please write the condition after return and check if the alert is trigger or not.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if(g_form.getValue('requested_environment_access') == "3d")
alert('hey buddy');
}
Thanks,
Faizeal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 06:32 AM
Hi Faizeal,
I have written the code outside loading function still not working:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {}
return;
}
if(g_form.getValue('requested_environment_access') == "3d")
{
alert('hey buddy');
}
Also, can you please let me know if the parameter we are comparing in getValue function must be name of that choice or label? Since field "
Hi Faizeal,
I have write the code outside loading function still not working:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {}
return;
}
if(g_form.getValue('requested_environment_access') == "3d")
{
alert('hey buddy');
}
Also, can you please let me know if the parameter we are comparing in getValue function must be name of that choice or label? Since field "requested_environment_access" is Select Box.