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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.228.35