Client script

Ram012
Tera Contributor

Prevent user from changing the state to closed in the List edit - use the Custom table.

 

Write client script but code is not working .

 

function onSubmit() {
   if (g_form.getValue('state') == 'Closed') {
    alert('You are not allowed to change the state to Closed');
    g_form.setValue('state', g_form.getOldValue('state'));
    return false;     // Prevent saving the record
  }
  return true;      // Allow saving the record
}
 
Any idea where the change the code exact any idea help me.
2 REPLIES 2

Vrushali  Kolte
Mega Sage

Hello @Ram012 , to prevent user updating the state on List view, you need to create a onCellEdit client script which will execute on list as below -

VrushaliKolte_0-1724046034493.png

 

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
  var saveAndClose = true;
 //Type appropriate comment here, and begin script below
 if(newValue == 7){ //please check the state value from backend.
	saveAndClose = false;
 }
 callback(saveAndClose); 
}

 

For more information on the onCellEdit client script, please refer below links -

 

https://www.basicoservicenowlearning.in/2019/12/client-script-in-servicenow.html

https://www.servicenow.com/community/developer-blog/learn-servicenow-oncelledit-client-script-servic...

 

If my answer solves your issue, please mark it as Accepted ✔️& Helpful👍!

Sandeep Rajput
Tera Patron
Tera Patron

@Ram012 You should use ACL with list_edit operation to prevent users from editing a specific field from the list. Please refer to https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0743628 to know more about this.