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

onCellEdit

The onCellEdit type of client script runs when a cell is edited on the list view of a table. This is the only client script type that does not run on the form view of a table. This type of client script is helpful to ensure that the rules you want to stick to are also enforced on list views of a table.

The script that ServiceNow provides for onCellEdit scripts looks a little different from the other client script types:

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
//Type appropriate comment here, and begin script below

callback(saveAndClose);
}

It is worth noting that these scripts could be for multiple records, as you can edit more than one using a list. As you can see, there are quite a few different parameters in this slightly different type of script. We'll have a look at what each one of those parameters gives us:

  • sysIDs: All of the sys_id unique IDs of the records being edited in an array.
  • table: The current table of the records being edited.
  • oldValues: The old values of all the cells being edited.
  • newValue: The new value to be put into all the cells being edited.
  • callback: A callback that allows the execution of further onCellEdit scripts or commits the change made if no further scripts exist. A true or false parameter can be passed, which will either allow further scripts and commit changes, or stop execution of further scripts and not commit the change, respectively.

These scripts tend to not be used that frequently, as server-side scripts like business rules can often be used to perform the functionality needed. Editing records in the list can also be a powerful tool for updating multiple records at once, so this is sometimes locked down to only certain users to prevent less knowledgeable users from causing issues.

An onCellEdit client script example can be viewed in Figure 3.4:

Figure 3.4: Sample onCellEdit client script

The client script in the preceding figure is an onCellEdit for the requested item table.  Again, for this type of script, ensure the Field name field is set to the value you require, as the script will only run on a change to this field in the list view.

主站蜘蛛池模板: 南汇区| 宿州市| 九寨沟县| 万全县| 海南省| 武乡县| 滕州市| 富宁县| 惠安县| 获嘉县| 图木舒克市| 惠来县| 虞城县| 垦利县| 宁河县| 靖安县| 鲁山县| 齐河县| 安吉县| 鹤岗市| 扬州市| 淮北市| 勃利县| 阿瓦提县| 龙口市| 开江县| 尖扎县| 墨玉县| 重庆市| 阿巴嘎旗| 宽甸| 平阴县| 咸丰县| 若尔盖县| 筠连县| 望城县| 剑阁县| 运城市| 历史| 曲周县| 呼伦贝尔市|