what is the difference between oncellEdit(),onchange()

siddirameshwar
Kilo Explorer

what is actual difference

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

OnChange CS runs when a particular field value changes on the form whereas oncellEdit runs when you edit field values from the list View.

https://docs.servicenow.com/bundle/london-application-development/page/script/client-scripts/concept...

 

-Pradeep Sharma

Ruhi Jibhyenka1
Mega Guru
Hi siddirameshwar, onChange() : An onChange() script can run when a particular field changes value or when the form is first drawn and no fields have changed value from previous script actions. As such, onChange scripts can potentially act as onLoad scripts with extra conditions. onCellEdit() : Scripts can be defined as onCellEdit to run on the client side when the list editor interacts with a cell. ServiceNow Community Community 10+ Toggle navigation what is the difference between onchange and oncelledit script - Developer Community Question what is the difference between onchange and oncelledit script by Abhinab Acharyya created 3y ago (edited 3y ago) in Developer Community HI, what is the difference between onchange and oncelledit script.. what are the scenario ion which each of them can be used Thanks Abhinab Upvote (0) Reply (3) 3299 Views Accepted Solution See this answer in context deepa Forum Level 4 • 3y ago Hi Abhinab, OnChange is triggered when you change any field from the record and oncelledit is triggered when you edit field values from the list View. You can restrict this celledit by writing oncelledit type of ACL. Below is example of oncelledit. Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy. Thanks, Deepa Helpful (5) Reply 3 Replies deepa Forum Level 4 • 3y ago Hi Abhinab, OnChange is triggered when you change any field from the record and oncelledit is triggered when you edit field values from the list View. You can restrict this celledit by writing oncelledit type of ACL. Below is example of oncelledit. Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy. Thanks, Ruhi.

Ruhi Jibhyenka1
Mega Guru

Hi siddirameshwar,

onChange() : An onChange() script can run when a particular field changes value or when the form is first drawn and no fields have changed value from previous script actions. As such, onChange scripts can potentially act as onLoad scripts with extra conditions.

For example, here is an onChange() script that notifies the user whenever the short description field on a form changes.
function onChange (control , oldValue , newValue , isLoading ) {
  alert('you changed short description from ' + oldValue  + ' to ' + newValue); }
To prevent an onChange() script from running when the form loads, add the following to the top of the script.
if(isLoading) { return; }

onCellEdit(): onCellEdit is a function used in the case of a list. If you want to write some script that should be executed on a list then you can do that by using onCellEdit function.

Here is  example for you:

The script below runs on the State field and prevents users from changing the State to closed in a list.  

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {

   var saveAndClose = true;

  if(newValue == 7){

  alert('Not allowed');

  saveAndClose = false;

  } else {

  saveAndClose = true;

  }

callback(saveAndClose); 

}

Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.

Thanks, 

Ruhi.