官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 合水县| 灌阳县| 项城市| 伊金霍洛旗| 麻江县| 崇文区| 庆城县| 巫山县| 分宜县| 东乡| 河东区| 尉氏县| 阳城县| 崇州市| 交城县| 抚州市| 西藏| 安平县| 南靖县| 梓潼县| 台北市| 通辽市| 勃利县| 阳信县| 昭平县| 宝丰县| 贡嘎县| 察雅县| 九龙城区| 德钦县| 弥渡县| 鲁甸县| 宜良县| 东莞市| 长乐市| 青浦区| 宜兰县| 清丰县| 松阳县| 卢龙县| 乐山市|