Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

ServiceNow Blog 04: What is Server-side scripting?

Not applicable

1) What is Server-side scripting

  • Server-side scripts are executed on server and database.
  • Following are examples:
  • Update the field when the record is inserted.
  • Setting a value on a field when parent record is updated.
  • Validate the role of logged in user.
  • Generate events,
  • Send an email.
  • Where to use server-side scripting: ACL, Script include, transform map, workflow, and business rule.

2) Server-side scripting examples:

  • Access control list
  • Business Rule
  • Ajax server scripts
  • Scripts action
  • Transform map
  • Ui Action
  • UI context menus
  • Workflow editor

3)Server-side Glide classes:

  • Glide Record: Glide Record is used for database operation. It’s used only on the server side. Syntax= create instance of Glide record class. Var gr = new GlideRecord(<table name>);.
  • Glide System: The Glide System is used to get information about the system and current logged-in users. It’s referred to as a variable “gs”. Syntax= gs. <GlideSystemMethod> ().
  • GlideAggregate: Glide Aggregate is used to perform aggregation operation on the database. It’s an extension of GlideRecord class. Provides database aggregation (COUNT, SUM, MIN, MAX, AVG) queries.
  • GlideDateTime: The scoped GlideDateTime class provides methods for performing operations on GlideDateTime objects. Use the GlideDateTime methods to perform date-time operations, such as instantiating a GlideDateTime object, performing date-time calculations, formatting a date-time, or converting between date-time.
  • GlideElement: The GlideElement API provides several convenient script methods for dealing with fields and their values. GlideElement methods are available for the fields of the current GlideRecord.
  • GlideElement - canCreate()GlideElement - canRead()GlideElement - canWrite()GlideElement - changes()GlideElement - changesFrom(Object value)GlideElement - changesTo(Object value)GlideElement - dateNumericValue().

4) Access control List:

  • An access control is a security rule defined to restrict the permission of a user from viewing and interacting with data.
  • CRUD Operations: Create, Read, update(write) and delete.
  • Access control definition – permission requirements: Object, operation, and permission.
  • Rule Types: Table.None, Table.field and Table. *.

5) Business Rule:

  • Server-side script
  • Runs when record is displayed, inserted, updated, or deleted or table is queried.
  • Table for business rules – sys_script.
  • Types of business rule: Before, after, Async and Display.
  • Two steps of business rule: when to run: the time when BR is configured for the record being modified or accessed and action.
  • The Type of database operation: insert, update, query and delete.
  • Global variables in business rules:
  • Current: current now this is something which basically store state of the same record you are working on.
  • Previous: Basically, captures the previous state of the record you are working on before any update or delete.
  • G_scratchpad:  object is available on display type of business. If you want field value from database server end on a client that time, use g_scratchpad.
  • Glidesystem:
  • Actions Performed by business rule:
  • Update the field value after creating the record as per the values of other fields.
  • Stop users updating or inserting records if invalid data is used.
  • Display information message when record is inserted.
  • Create child tasks when parent is created.

 

0 REPLIES 0