Server side APIs

Just like on the client, scripts that execute on the server a particular set of APIs that they have access to. This API suite is broader than the client side API in part because making an API available on the client requires sending code from the server to the client, for possible execution, which can slow page loads, and also in part because server scripts execute on the server! The server has an extremely low-latency connection to the database, which makes more robust scripting possible and much more efficient.

There are two sets of APIs: scoped, and legacy. Scoped APIs are a subset of the legacy API. They are the only APIs available within scoped applications, and do have some limitations. These limitations however, are becoming fewer and fewer with every new version of ServiceNow.

Let's go over some of the APIs and objects available on the server:

  • GlideAggregate: This is an extension of the GlideRecord class, used for creating database aggregation queries such as SUM, COUNT, MIN, and MAX. For example, you can run a query with a given filter (say, all items associated with a given ticket) and get a SUM of the cost of these items in order to determine the total cost of the parent ticket.
  • GlideDateTime: This is a class meant to help with the usage of glide_date_time fields, as well as comparing one date and time to another date and time, or formatting a date/time from a string into a date/time object that can be used for time zone conversion and date/time calculations.
  • GlideDateTime: This is very similar to the GlideDate class, which is just for dates without times associated
  • GlideRecord: This is probably the most ubiquitous class in ServiceNow, and it is both a server side and client side API. It is vastly different in behavior and capability on the client, but on the server it is a powerful and efficient means of querying the database for a given record or set of records. As you can imagine, getting and setting data in the database is something you might need to do quite often in a platform like ServiceNow.
  • GlideElement: This is a class referencing a specific field on a client side GlideRecord object. To put it another way, each GlideRecord object contains one property (a GlideElement object) for each field on that record. This API provides methods for interacting with these fields and their values.
  • gs: This is a reference to GlideSystem (which has no constructor method). It provides methods with all sorts of useful system functionality, including getting system properties, logging information to the system logs, and checking user permissions.
Objects that are meant to be instantiated have a constructor method. This method must be called using the new keyword. When I write var gr = new GlideRecord('table_name');, the new keyword calls the constructor method of the GlideRecord class. This constructor is usually a function in the class called initialize, which takes the argument table_name that we specified in our call. The constructor then modifies properties of the object and returns the resulting constructed object to our variable, gr.
  • GlideSession: This is a server side object that corresponds to the currently signed-in user's session. It provides methods to get the roles associated with a user, as well as set and retrieve data associated with their particular session. You can get an instance of the GlideSession object for the current user's session by using the getSession() method of the GlideSystem API like so: var session = gs.getSession();.

Server side scripts that operate on a specific record (such as Business Rules or advanced conditions fields), also often have access to a pre-defined variable called current. This is an instance of the GlideRecord object which contains the data relating to the record upon which the script is executing.For example, say you have a Business Rules that executes on the incident table, and is triggered whenever the State field changes value. If you then go to the incident table, open up a record, and change the State field value, then the Business Rule will execute. when it does, in the context of the script that that Business Rule runs, the current object will correspond to the record that you just modified.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.249.104