
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 03:31 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 03:53 PM
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 👍✅
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 09:29 AM
@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.