Best Practices with Glide System

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2022 05:07 AM
What is Glide System?
- Glide System API running from server side
- This API will provides different methods to get information about the system, the current Logged in user, etc.
- The Glide System global object is gs
- Many of the Glide System methods facilitate the easy inclusion of dates in query ranges
- Often used in filters and reporting.
Glide System Methods
Glide System | |
addInfoMessage() | endOfLastMonth() |
addErrorMessage() | endOfLastWeek() |
getUser() | endOfLastYear() |
getUserName() | endOfNextMonth() |
getUserID() | endOfNextWeek() |
getUserDisplayName() | endOfNexYear() |
hasRole() | endOfThisYear() |
error() | endOfThisQuarter() |
eventQueue() | endOfThisMonth |
eventQueueScheduled() | hoursAgo() |
generateGUID() | hoursAgoEnd() |
getErrorMessage() | hoursAgoStart() |
getSession() | minutesAgoEnd() |
getSessionID() | minutesAgoStart() |
include() | monthsAgo() |
Info() | monthsAgoStart() |
isDebugging() | nil() |
isInteractive() | yearsAgo() |
isLoggedIn() | yesterday() |
isMobile() | Warn() |
setProperty() | tableExists() |
setRedirect() | getAvatar() |
Practically Work with these all methods |
Glide System Exercises
- Navigate to System Definition
- Open Scripts – Background Application
- Write code into given space.
1. Working with addInfoMessage () method
This method is used to add an info message for the current session.
This method is not supported for asynchronous business rules.
gs.addInfoMessage ('Start date should be always before end Date');
2. Working with addErrorMessage () method
This method is used to add an error message for the current session.
gs.addErrorMessage (‘please provide valid info');
3. Working with getUser () method
Returns a reference to the user object for the current user.
var currentUser = gs.getUser();
gs.print(currentUser.getEmail());
4. Working with getUserDisplayName () method
Return current user display name
gs.print (gs.getUserDisplayName ());
5. Working with getUserID () method
Return current user sys_id
gs.print (gs.getUserID ());
6. Working with getUserName () method
Display current user user name
gs.print (gs.getUserName ());
7.Working with getUserNameByUserID () method
Returns the username based on a user ID.
gs.print (gs.getUserNameByUserID ('admin'));
8. Working with hasRole () method
Define if the current user has at least one of the role assigned to current user
gs.print (gs.hasRole ());
9.Working with hasRoleInGroup () method
Define if the current user has the specified role within a specified group.
var group = new GlideRecord ('sys_user_group');
group.addQuery ('name', 'software');
group.setLimit (1);
group.query ();
if (group.next ()) {
if (gs.hasRoleInGroup ('itil', group)) {
gs.print('User has role in group');
} else {
gs.print ('User does NOT have role in group');
}
}
10.Working with isInteractive () method
It will checks if the current session is interactive or not
- Interactive session is when a user logs in using the service now log-in screen
- Non-interactive session is using a SOAP request to retrieve data from servicenw platform.
gs.print (gs.isInteractive ());
11.Working with getAvatar () method
Displays the file path to the current user's avatar.
var userPhoto = gs.getUser ().getAvatar ();
gs.addInfoMessage ('User avatar ID: ' + userPhoto);
12.Working with flushMessags () method
This method will clears all session messages saved using addErrorMessage () or addInfoMessage ().
Session messages are shown at the top of the form. In client side scripts, use g_form.clearMessages () to remove session messages.
gs.flushMessages ();
13.Working with beginningOfLastMonth () method
This method will get the date and time for the beginning of last month in GMT.
gs.print (gs.beginningOfLastMonth ());
14.Working with beginningOfLastWeek () method
Returns the date and time for the beginning of last week in GMT.
gs.print (gs.beginningOfLastWeek ());
15.Working with beginningOfNextMonth () method
Returns the date and time for the beginning of next month in GMT.
gs.print (gs.beginningOfNextWeek ());
16.Working with beginningOfNextWeek () method
Gets the date and time for the beginning of next week in GMT.
gs.print (gs.beginningOfNextWeek ());
17.Working with beginningOfNextYear () method
Returns the date and time for the beginning of next year in GMT.
gs.print (gs.beginningOfNextYear ());
18.Working with beginningOfThisMonth () method
Get the date and time for the beginning of this month in GMT.
gs.print (gs.beginningOfThisMonth ());
19.Working with beginningOfThisQuarter () method
Returns the date and time for the beginning of this quarter in GMT.
gs.print (gs.beginningOfThisQuarter ());
20.Working with beginningOfThisWeek () method
Returns the date and time for the beginning of this week in GMT.
gs.print (gs.beginningOfThisWeek());
21.Working with beginningOfThisYear () method
Returns the date and time for the beginning of this year in GMT.
gs.print (gs.beginningOfThisYear());
22.Working with beginningOfToday () method
Retrieves the date and time for the beginning of today in GMT.
gs.print (gs.beginningOfToday());
23.Working with beginningOfTomorrow () method
Retrieves the (UTC) beginning of tomorrow adjusted for the timezone of the current session
gs.print (gs.beginningOfTomorrow());
24.Working with beginningOfYesterday () method
Retrieves the date and time for the beginning of yesterday in GMT.
gs.print (gs.beginningOfYesterday ());
25.Working with daysAgo () method
Returns a date and time for a certain number of days ago.
var gdt = new GlideDateTime()
gs.print (gs.daysAgo(4));
26.Working with daysAgoEnd () method
Returns a date and time for the end of the day a specified number of days ago.
var gdt = new GlideDateTime()
gs.print (gs.daysAgoEnd (10));
27.Working with daysAgoStart () method
Returns a date and time for the beginning of the day a specified number of days ago.
var gdt = new GlideDateTime ()
gs.print (gs.daysAgoStart (4));
28. Working with endOfLastMonth () method
Returns the date and time for the end of last month in GMT.
gs.print(gs.endOfLastMonth());
29.Working with endOfLastWeek () method
Returns the date and time for the end of last week in GMT.
gs.print (gs.endOfLastWeek());
30. Working with endOfLastYear () method
Returns the date and time for the end of last year in GMT.
gs.print (gs.endOfLastYear ());
31.Working with endOfNextMonth() method
Returns the date and time for the end of next month in GMT.
gs.print (gs.endOfNextMonth ());
32.Working with endOfNextWeek () method
Gets the date and time for the end of next week in GMT.
gs.print (gs.endOfNextWeek ());
33.Working with endOfNextYear () method
Returns the date and time for the end of next year in GMT.
gs.print (gs.endOfNextYear ());
34.Working with endOfThisMonth () method
Returns the date and time for the end of this month in GMT.
gs.print (gs.endOfThisMonth());
35.Working with endOfThisQuarter () method
Returns the date and time for the end of this quarter in GMT.
gs.print (gs.endOfThisQuarter ());
36.Working with endOfThisWeek () method
Returns the date and time for the end of this week in GMT.
gs.print (gs.endOfThisWeek ());
37.Working with endOfThisYear () method
Returns the date and time for the end of this year in GMT.
gs.print (gs.endOfThisYear ());
38.Working with endOfToday () method
Retrieves the date and time for the end of today in GMT.
gs.print (gs.endOfToday ());
39.Working with endOfTomorrow () method
Retrieves the date and time for the end of tomorrow in GMT.
gs.print (gs.endOfTomorrow ());
40.Working with endOfYesterday () method
Retrieves the date and time for the end of yesterday in GMT.
gs.print (gs.endOfYesterday ());
41.Working with getDisplayColumn () method
Retrieves the display column for the table.
gs.print (gs.getDisplayColumn ('incident'));
42.Working with getErrorMessage () method
This mesthod will get returns the list of error messages for the perticular session that were added by addErrorMessage ().
var errorMsg = gs.addErrorMessage ('Please fill mandatory fields');
gs.print (gs.getErrorMessages (errorMsg));
43.Working with getInfoMessage () method
Retrieves the list of info messages for the session that were added by addInfoMessage ().
var infoMsg = gs.addInfoMessage ('Info Message');
gs.print (gs.getInfoMessage (infoMsg);
44.Working with getInitials () method
It will return the user’s initials
var userInitials = gs.getUser ().getInitials();
gs.addInfoMessage ('User initials: ' + userInitials);
45.Working with getMessage () method
Retrieves translated messages to display in the User Interface.
If the specified string exists in the database for the current language, then the translated message is returned. If the specified string does not exist for the current language, then the English version of the string is returned. If the string does not exist at all in the database, then the ID itself is returned.
If the UI message has a tick ('), there may be issues with the message in the script; to escape the ticks ('), use getMessageS (String, Object).
var myMsg = gs.getMessage ('This is my own message');
gs.print (myMsg);
46.Working with getSession () method
Returns a GlideSession object.
gs.print (gs.getSession ());
47.Working with getSessionID () method
Returns the GlideSession Session ID.
gs.print (gs. getSessionID ());
48.Working with hoursAgo() method
Returns a date and time for a certain number of hours ago.
gs.print (gs.hoursAgo (7));
49.Working with hoursAgoStart () method
Returns a date and time for the start of the hour a certain number of hours ago.
gs.print (gs.hoursAgoStart (2));
50. Working with isFirstDayOfMonth () method
This method will checks whether the date is the first day of the month.
gs.print (gs.IsFirstDayOfMonth (2020-01-25));
51.Working with isFirstDayOfWeek () method
Checks whether the date is the first day of the week. This uses the ISO standard of Monday being the first day of the week.
gs.print (gs.isFirstDayOfWeek (2020-04-12));
52.Working with isFirstDayOfYear () method
Checks whether the date is the first day of the year.
gs.print (gs.isFirstDayOfYear(2020-04-12));
53.Working with isLastDayofMonth () method
Checks whether the date is the last day of the month.
gs.print (gs.isLastDayOfMonth(2020-04-19));
54.Working with isLastDayofWeek () method
Checks whether the date is the last day of the week.
gs.print (gs.isLastDayOfWeek (2020-04-19));
55.Working with isLastDayofYear () method
Checks whether the date is the last day of the year.
gs.print (gs.isLastDayOfWeek (2020-04-19));
56.Working with lastWeek () method
Returns the date and time one week ago in GMT.
gs.print (gs.lastWeek ());
57.Working with now () method
Returns the current date in UTC.
gs.print (gs.now ());
58.Working with nowDateTime () method
Gets the current date and time in the user-defined format.
gs.print (gs.nowDateTime ());
59.Working with nowDateTime () method
Returns the current date and time in UTC format.
gs.print (gs.nowNoTZ ());
60.Working with setProperty () method
Sets the specified key to the specified value.
gs.setProperty("glide.foo","bar","foo");
gs.info (gs.getProperty("glide.foo"));
61. Working with setRedirect () method
Sets the redirect URI for this transaction, which then determines the next page the user will see.
gs.setRedirect("com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=d41ce5bac611227a0167f4bf8109bf70&sysparm_user=" + current.sys_id + "&sysparm_email=" + current.email);
Regards,
Vaishnavi Lathkar
@
- 1,404 Views