- Mastering ServiceNow Scripting
- Andrew Kindred
- 339字
- 2021-06-24 19:08:39
GlideElement
GlideElement provides methods for dealing with the fields in a GlideRecord object. This class is one of the smaller ones in ServiceNow.
One very handy set of methods in this class is detecting changes to a field. This is very helpful in closing down records. Sometimes we may want to run some script on closure of the record, but not every time the record is updated. This is when the changesTo method can be used. We'll assume we are using an incident, in this case where the closed state is 7:
if (current.state.changesTo('7')) {
//Run some closure script
}
This preceding example will allow for some script to run when the record is closed, but only when it moves to being closed. If the closed record is subsequently updated, then this script will not run again. That is why this method is so helpful. You can also use changes and changesFrom methods as part of this set.
You may or may not be aware of what current refers to at this point, but we will take a closer look at this when we look at business rules in Chapter 5, Introduction to Server-Side Scripting.
Another helpful set of methods in GlideElement is checking whether a user is able to create, read, or write to records. We can use this to see whether a user should be able to perform these actions, which can be very helpful in UI action conditions.
Let's see how it works:
if (current.canCreate()) {
//Run some creation script for the current record type
}
This will check whether the logged-in user is able to create a record of the current type (incident, change request, and so on) and, if so, then run the script inside the if statement. We can also use the canRead and canWrite methods in a similar way.
With GlideElement being a smaller class, it is not as well used as some of the other server-side classes, but some of its methods are very helpful, particularly in UI actions.
- AutoCAD繪圖實用速查通典
- Mastering Spark for Data Science
- 網上沖浪
- 錯覺:AI 如何通過數據挖掘誤導我們
- 反饋系統:多學科視角(原書第2版)
- 城市道路交通主動控制技術
- 最后一個人類
- PostgreSQL Administration Essentials
- 21天學通Java
- 新手學電腦快速入門
- Implementing Oracle API Platform Cloud Service
- JSP從入門到精通
- TensorFlow Reinforcement Learning Quick Start Guide
- 中國戰略性新興產業研究與發展·增材制造
- Working with Linux:Quick Hacks for the Command Line