Need help writing an OnCell Edit Script on Hardware Table

Ankita NA
Tera Contributor

Hi,

I need to write an OnCellEdit script on " Hardware Status " field on hardware table.

 

Old Requirement: Users which doesn't have ecmdb_admin role can't change the Hardware status to "Stolen/Lost".

For that I wrote the below OnCellEdit client script on Hardware table for field Hardware status.

 

AnkitaNA_0-1694077820856.png

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
  var saveAndClose = true;  
    if (newValue == 'stolen' && g_user.hasRole('ecmdb_admin')){
        callback(true);
    }
    else if (newValue != 'stolen'){
        callback(true);
    }
    else {
        callback(false);
        alert("Not allowed to update the Hardware Status to Stolen/Lost");
    }  
 
 callback(saveAndClose);
 
 
 
To this I have to add a condition 
If the environment is Development or Test , then Users which doesn't have ecmdb_admin role can't change the Hardware status to "Stolen/Lost". so please help me with the new condition, how can I add the new condition in the working script.
AnkitaNA_1-1694078026207.png

 

 
Thanks,
Ankita
5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Ankita NA 

why not handle the list edit via list_edit ACL for that field?

you can handle this using conditions of ACL

Did you try that?

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

Ho @Ankur Bawiskar  I have not tried that, will try implementing. But the query is cannot it be done by onCellEdit client script with one additional condition.?

@Ankita NA 

I am saying it's recommended to use list_edit ACL here with minimal script

you cannot access other field value using g_form using onCellEdit so you cannot determine what's the environment.

using onCell edit you can access only the field value on which onCell Edit is written

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

Noted