This type of client script runs when the list editor changes a cell value. Script runs when a particular field value on a list changes. Applies to all records selected.
In onCellEdit() client script we will get OOB parameters/Objects. Let me explain you each object in details.
Request you to watch it for better understanding.
A. sysIDs: It consist an array of the sys_ids for all items being edited.
B. table: The table of the items being edited.
C. oldValues: The old values of the cells being edited.
D. newValue: The new value for the cells being edited.
E. callback: A callback that continues the execution of any other related cell edit scripts.
If true is passed as a parameter, the other scripts are executed or the change is committed if there are no more scripts. If false is passed as a parameter, any further scripts are not executed and the change is not committed.
Note: onCellEdit() scripts do not apply to List Widgets on homepages or dashboards.Now lets take a look on real word example
Real World Scenario
Requirement: Prevent state being edited from list view of incident if state marked as Resolved or Closed.
Solution: create onCellEdit client script and write below code.
function onCellEdit(sysIDs, table, oldValues, newValue, callback){ var saveAndClose = true; if(newValue == 6) { //Resolved alert("You cannot change the State to 'Resolved' from a list"); saveAndClose = false; } if(newValue == 7) { //Closed alert("You cannot change the State to 'Closed' from a list"); saveAndClose = false; } callback(saveAndClose); }