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

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.

主站蜘蛛池模板: 英山县| 宜宾县| 买车| 阿拉善右旗| 绥化市| 仁布县| 灵山县| 屯留县| 个旧市| 色达县| 昌江| 长汀县| 安龙县| 襄汾县| 马尔康县| 巍山| 南郑县| 禄丰县| 聂荣县| 通化市| 读书| 平罗县| 濮阳市| 南靖县| 揭西县| 宣武区| 交口县| 桐城市| 淮滨县| 吉安市| 青田县| 新建县| 健康| 阿鲁科尔沁旗| 渭南市| 天峻县| 安溪县| 松桃| 永吉县| 佛坪县| 松潘县|