The GlideSystem Object and You

Not applicable

Whenever you are writing server side business rules, you have access to the GlideSystem object. You can reference it in script as gs.

For example, you are probably familiar with:

gs.getUserID();

The GlideSystem object has a lot of functionality packages into it though, not all of it obvious, so this is an attempt to outline some of the more powerful features you might have been missing out on.

Date/Time Functions:

gs.now() -- returns the current date (no hours/minutes/seconds)
gs.nowDateTime() -- returns the current date/time (with hours/minutes/seconds)

gs.daysAgo() -- returns a date/time offset by n days from today.

Example:
gs.daysAgo(30) -- returns 30 days ago
gs.daysAgo(-30) -- returns 30 days in the future (because of the negative)

Commonly used in queries e.g.
gr.addQuery('opened_at', '>', gs.daysAgo(30));

gs.monthsAgo() -- returns a date/time offset n by n months from today
gs.minutesAgo() -- returns a date/time offset by n minutes from today
gs.quartersAgo() -- returns a date/time offset by n quarters from today

gs.beginningOfLastMonth() -- this set should be self explanatory
gs.beginningOfLastWeek()
gs.beginningOfLastYear()
gs.beginningOfNextMonth()
gs.beginningOfNextWeek()
gs.beginningOfNextYear()
gs.beginningOfThisMonth()
gs.beginningOfThisWeek()
gs.beginningOfThisYear()
gs.beginningOfToday()
gs.beginningOfYesterday()


gs.endOfLastMonth()
gs.endOfLastWeek()
gs.endOfLastYear()
gs.endOfNextMonth()
gs.endOfNextWeek()
gs.endOfNextYear()
gs.endOfThisMonth()
gs.endOfThisWeek()
gs.endOfThisYear()
gs.endOfToday()
gs.endOfYesterday()

gs.getDateFormat() -- returns the current user's date format
gs.getDateTimeFormat() -- returns the current user's date/time format

User Information

gs.getUser() -- returns the current user object. Note that this is not a glide record
gs.getUserID() -- returns the sys_id of the current user e.g. abc...123
gs.getUserName() -- returns the login name of the current user e.g fluddy
gs.getUserDisplayName() -- returns the display name of the current user e.g. Fred Luddy
gs.getUserNameByUserID() -- returns the full name matching a given user name. The function name is somewhat misleading as it would lead you to believe you should pass in a sys_id. In fact it wants a username e.g. fluddy

Messaging

gs.print() -- write a message to the file system log
gs.log() -- writes a message to the file system log and the database log. Significantly higher performance impact than gs.print()
gs.addInfoMessage() -- puts out an information message (black)
gs.addErrorMessage() -- puts out an error message (red)

Security

gs.hasRole() -- returns true or false if the current user has the provided role
gs.isInteractive() -- returns true if the current session is reacting to a user doing something. Returns false if the current session is running in a background task (like a scheduled job or an escalation)
gs.isLoggedIn() -- returns true if the current session is logged in, else false

2 REPLIES 2

Not applicable

These things are life savers. Keep them comming. :cool:


alan_lowrance
Mega Guru

Hey Pat, thanks for all the awesome stuff you've built for the platform!   I was just wondering what the thinking in gs.getUserNameByUserID() was when it does the opposite of what you would need it to do.   I want to be able to feed in a SysID and get back a username without querying the GlideRecord 😞 guess I have to make my own script include for it.