
- 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-20-2023 03:48 PM
Hi @G24 ,
Could you please take a look at this article if it helps:
https://www.servicenow.com/community/developer-forum/jslog-ok-is-there-a-jswarn-method/m-p/1785975
Please mark my answer helpful & accepted solution if it resolves your query.
Thanks,
Danish
- 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 06:33 AM
@AnveshKumar M Thanks, but "jslog()" is not defined apparently. Is that unavailable on the Service Portal???
Super frustrating.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 07:18 AM
@G24 Yes! It is not available in ServicePortal. Refer the KB from ServiceNow below.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0728539
Anvesh