- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 10:24 PM
Hi All ,
Everytime i write Catalog Onchange cleint script i get Error as ' There is a JavaScript error in your browser console '
,Could you any one let me know the issue .
My Requirement is a message ( Hi Urgency 2 ) should come in service portal when in the catalog name' Incident' field name 'urgency' choice '2- High ' is selected similarly for if choice '3-Medium' then message ( Hi urgency 3) and for choice '4-Low' then message should come as ( Hi urgency 4) .
Also need suggestion are we not suppose to use Onchange client script on service portal ?
i have tried basic message to check if it works or not but got same error :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue==2)
{
g_form.addInfoMessage(Hi);
}
//Type appropriate comment here, and begin script below
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 10:31 PM
Place your message in quotes.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue==2)
{
g_form.addInfoMessage('Hi');
}
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 10:42 PM
Hello,
As Muhammad correctly pointed out it is because of the info message not being in the quotes:-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue==2)
{
g_form.addInfoMessage('Hi');
}
}
Please mark answer correct/helpful based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 10:31 PM
Place your message in quotes.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue==2)
{
g_form.addInfoMessage('Hi');
}
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 10:33 PM - edited 11-13-2022 10:39 PM
hello @ServiceNow10sun ,
can you please check the UI type of the catalog client script ?
is it desktop or service portal or both ?
also you need to put HI in quotes g_form.addInfoMessage('Hi');
Addition to this you need to change the 2nd line to this below line as per OOB syntax
if (isLoading || newValue == '') {
if it is desktop please change it to all and try
Hope this helps
Mark the answer correct if it helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 10:34 PM
OnChange do work on service portal.
Your 1st if statement which comes OOB with client script has a missing "=". Try below:
if (isLoading || newValue === '')
Also paste the screenshot from console to check the exact error.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 10:42 PM
Hello,
As Muhammad correctly pointed out it is because of the info message not being in the quotes:-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue==2)
{
g_form.addInfoMessage('Hi');
}
}
Please mark answer correct/helpful based on Impact.