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

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.

主站蜘蛛池模板: 永州市| 十堰市| 平南县| 和龙市| 宜宾市| 黄陵县| 元氏县| 巩义市| 潮州市| 潜山县| 南投县| 麦盖提县| 车致| 北碚区| 大悟县| 邵阳县| 凤冈县| 上蔡县| 昌黎县| 太康县| 邢台县| 芦山县| 砀山县| 岚皋县| 南城县| 额济纳旗| 桐梓县| 香港| 玛多县| 启东市| 丰城市| 琼结县| 吉木乃县| 赤城县| 基隆市| 吴桥县| 兴隆县| 新疆| 大连市| 赤壁市| 桐柏县|