Useful JavaScript Methods

jesusemelendezm
Mega Guru

I am creating a list of useful JavaScript methods to accomplish multiple tasks in ServiceNow. Those methods that should be unforgettable and kept handy to use in any scripting area of ServiceNow.

Just today while working with date fields and inbound rules, I used three useful methods toLowerCase(), indexOf() and getNumericValue(). The toLowerCase() and IndexOf() methods to set a condition for an inbound action to   run only when a certain email address was found in the recipients. This was the condition: email.recipients.toLowerCase().indexOf('email01@company.com')   > -1

The getNumericValue() method was very useful when I was intending to compare two date fields. The statement that I wrote was the following: var task_due_date = current.due_date.getGlideObject().getNumericValue(); // this returns the int value of the date and I could easily compare it against another variable that had stored int value from another date type field.

Please share!

Thank you.

5 REPLIES 5

Pritam Mangrulk
Mega Contributor

Hi,

You can also check below article:

https://glidecenter.com/most-used-javascript-string-functions-in-servicenow-scripting/

 

Thanks,

Pritam