jslog.. ok, is there a jswarn method?

xiaix
Tera Guru

I use console.warn() everywhere in client scripts.  It really helps debugging, especially because .warn() stands out so wonderfully.

Example:

find_real_file.png

 

I'm not a fan of the find_real_file.png that I keep getting though.

I would use jslog() , but then I lose the color and stand out of console.warn().

Is there anything like a jswarn() ?  Or, is there a way to log to the browser's console natively from SN that I could give it some highlighting to stand out?

1 ACCEPTED SOLUTION

Trevor Muhl
Kilo Sage

If you don't mind having extra comments in your code, you can disable the ESLint rule responsible for those warnings.

Disable for one line:

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

Disable for multiple lines (and then re-enable, if desired):

/* eslint-disable no-console */
... many console statements here
/* eslint-enable */

Here is a screenshot of the results:

find_real_file.png

View solution in original post

9 REPLIES 9

Michael Jones -
Giga Sage

Unfortunately, I've not seen anything native to ServiceNow that encompasses this type of logging. I, too, use console.warn() and console.error() to make certain statements stand out in the console, but using chrome and the developer tools I haven't noticed anything "unexpected console statement" messages. 

The only client-side function I see anywhere for logging is jslog(), which I use primarily when I need to evaluate something using ServiceNow's console.

Wish I had a better answer! 

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

The "Unexpected console statement" messages come from ServiceNow.  Yeah, I figured there wasn't anything like jswarn(), but didn't hurt to ask! 🙂

I'll just stick with console.warn() and ignore the SN script warnings find_real_file.png

RAHUL Khanna1
Mega Guru

May be ypu can try this 

 

const style = 'font-weight: bold; font-size: 50px;color: red; text-shadow: 3px 3px 0 rgb(217,31,38) , 6px 6px 0 rgb(226,91,14) , 9px 9px 0 rgb(245,221,8) , 12px 12px 0 rgb(5,148,68) , 15px 15px 0 rgb(2,135,206) , 18px 18px 0 rgb(4,77,145) , 21px 21px 0 rgb(42,21,113)';

console.log('%c Rainbowww!', style);
console.log(' Test Comments', 'background: #222; color: #bada55');
console.log("HELLO-11111");

console.log('%c Oh my heavens! ', 'background: #415; color: #bada65');

Ok. That's pretty cool! Maybe wrapped in a function and made as part of a global ui script...neat.

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!