Prevent editing the fields via List Editor (cell edit) only when the Type is Standard

vivek11
Tera Contributor

Hi Team,

I need script for OnCellEdit client script for below requirement as i dont want to Write ACL for it due to some issues.


Prevent editing the following fields via List Editor (cell edit) only when the Type is Standard:

description

implementation_plan

test_plan (aka "Test and Validation Plans")

backout_plan

Can Someone please help me thanks in Advanced

1 ACCEPTED SOLUTION

@vivek11 

I already shared another option i.e. use before update business rule

But remember this will impact and stop user from saving when fields get updated from form as well.

Any reason not to use list_edit ACL?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

13 REPLIES 13

J Siva
Tera Sage

Hi @vivek11 
You need to use a client-callable Script Include to check the change type and return the appropriate response  back to the client script..
In your onCellEdit client script, use GlideAjax and pass the sys_id of the record to the Script Include.

Regards,
Siva

vivek11
Tera Contributor

Hi @J Siva 

Thank you for Quick reply,

If possible, Could you please provide me code.. It is not working for me?

Thank you.

Community Alums
Not applicable
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
  var saveAndClose = true;

  // Fields you want to block in list editor
  var blockedFields = ['description', 'implementation_plan', 'test_plan', 'backout_plan'];

  // Check if the edited field is in blocked list
  if (blockedFields.indexOf(newValue.changedField) > -1) {
    // Check the Type value; it might be in oldValues or newValue depending on your list
    var typeValue = oldValues.type || newValue.type;

    if (typeValue == 'Standard') {
      alert('Editing this field is not allowed when Type is Standard.');
      saveAndClose = false; // Block the change
    }
  }

  callback(saveAndClose);
}

 

  • Checks if the field you’re trying to edit is one of the blocked fields.

  • Checks if the record’s Type is Standard.

  • If both match, shows an alert and cancels the edit

 

Hi @Community Alums 

I have tried it but not able to find anything, It is not working for me...
Could you please help me