can give me one example of oncellEdit?

ram2497
Tera Contributor

can give me one example of oncellEdit?

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

onCellEdit is a function that is 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.   Hope this helps.

 

 

 

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

 

    var saveAndClose = true;

 

 

 

  if(newValue == 7){

 

  alert('Not allowed');

 

  saveAndClose = false;

 

  } else {

 

  saveAndClose = true;

 

  }

 

 

 

callback(saveAndClose);

 

}

 

Regards,

Sachin

View solution in original post

3 REPLIES 3

vinothkumar
Tera Guru

OnCellEdit Client script is typically used, when you want your client script logic to run, if the user is changing in the list edit view of servicenow.

 

While onLoad and OnChange used to work on the form layout.

sachin_namjoshi
Kilo Patron
Kilo Patron

onCellEdit is a function that is 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.   Hope this helps.

 

 

 

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

 

    var saveAndClose = true;

 

 

 

  if(newValue == 7){

 

  alert('Not allowed');

 

  saveAndClose = false;

 

  } else {

 

  saveAndClose = true;

 

  }

 

 

 

callback(saveAndClose);

 

}

 

Regards,

Sachin

SumitS
Tera Contributor
Select Field name - impact & run this script, whenever impact in cell is changed to 1 urgency would be set to 1 autometically


function
onCellEdit(sysIDs, table, oldValues, newValue, callback) {
    var saveAndClose = true;
if(newValue=='1') {
 callback(saveAndClose);
 alert("Imapct is changed to 1");
 g_form.setValue('urgancy','1');
 callback(saveAndClose);
}}