Unexpected Console Statement - BUT WHY???

G24
Kilo Sage

I wrote some happy sys_ui_script that runs on the Portal.  Since I'm on the portal, if something goes wrong, I want to write a message to the browser log.  But when I do so, I am told "Unexpected console statement" by the script field.  I would like to know WHY?  Why is this statement "unexpected"?  Since it works fine?

 

0005.png

 

0006.png

 

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @G24 ,

 

This is how the linting configured in ServiceNow editor fields intentionally. Why because the console.warn() or console.log() messages are visible to any logged in user if they use Developer Tools in the browser. These console messages are not required for end users.

 

And ServiceNow have an inbuilt alternative to console.log() which is jslog(). The log messages will be shown in the console if the logged in user is an admin user. Ofcourse there is no alternative to console.warn().

 

If you still want to use console.warn() and don't want the editor to throw that Unexpected message, try enclosing those between these lint rules.

/* eslint-disable-next-line no-console */

 

OR

 

/* eslint-disable no-console */
/* eslint-enable */

 

 

Please mark my answer helpful and accept as solution if it helped you 👍

 

Thanks,
Anvesh

View solution in original post

5 REPLIES 5

@AnveshKumar M Thank you.

 

But I must be missing a puzzle piece somewhere.  I don't understand why things are so fragmented between the service portal and the platform UI.  If code is running on the Client, why are HALF of the objects available in the context of the Portal, and the other HALF available only in the context of the Platform UI?  Why is this so difficult?  What am I missing?

 

I will NEVER use jslog() since it is inexplicably missing in the context of Service Portal script.