There is a JavaScript error in your browser console- Catalog Client script in Service Portal

ServiceNow10sun
Giga Guru

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

 

@Saurav11 @Ankur Bawiskar 

2 ACCEPTED SOLUTIONS

Muhammad Khan
Mega Sage
Mega Sage

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

View solution in original post

Saurav11
Kilo Patron
Kilo Patron

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. 

View solution in original post

5 REPLIES 5

Muhammad Khan
Mega Sage
Mega Sage

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

Mohith Devatte
Tera Sage
Tera Sage

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

RaghavSh
Kilo Patron

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

Saurav11
Kilo Patron
Kilo Patron

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.