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

@Ankita NA 

Thank you for marking my response as helpful.

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