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

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.

主站蜘蛛池模板: 九龙坡区| 松潘县| 锡林浩特市| 锡林郭勒盟| 民勤县| 连城县| 汉源县| 深圳市| 开江县| 湟中县| 太保市| 清镇市| 清远市| 阿拉善左旗| 鲁甸县| 台东县| 治多县| 堆龙德庆县| 宝丰县| 和龙市| 麻栗坡县| 东安县| 墨玉县| 扎囊县| 大姚县| 涟水县| 西峡县| 怀仁县| 怀柔区| 乌拉特前旗| 剑河县| 刚察县| 上犹县| 海伦市| 天峨县| 吐鲁番市| 宣化县| 清远市| 江口县| 巴林右旗| 定远县|