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

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.

主站蜘蛛池模板: 福建省| 城市| 平泉县| 汝州市| 水城县| 疏附县| 霍州市| 澄江县| 永清县| 万载县| 剑河县| 旅游| 通化县| 夏邑县| 防城港市| 海原县| 交城县| 香河县| 肃宁县| 睢宁县| 铁岭县| 五莲县| 扬州市| 常山县| 乌拉特后旗| 汕头市| 安远县| 绥滨县| 江源县| 张家川| 米泉市| 商城县| 新邵县| 桦川县| 安宁市| 汶川县| 平潭县| 阿荣旗| 册亨县| 寻乌县| 仁寿县|