Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

ON CELL EDIT client script not working pls help me , where i am wrong

Anjali yadav1
Tera Contributor

Anjaliyadav1_0-1712486314354.png

 

1 ACCEPTED SOLUTION

Ranjit Nimbalka
Mega Sage

Hi @Anjali yadav1 

 

please try below script that will work for you.

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
    var saveAndClose = true;
    var isAdmin = g_user.hasRole('admin');
   
    if ((isAdmin == false && newValue == 2) || (isAdmin == false && newValue == 3)) {
        alert("Not allowed to set this state");
        saveAndClose = false;
    }

    callback(saveAndClose);
}
Screenshot (6).png
 
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Ranjit

View solution in original post

4 REPLIES 4

siva krishna RM
Tera Contributor

Hello @Anjali yadav1 ,

 

Scripts seems to be correct. Could you please verify you have selected field name as state and UI type as one of destop/All.

 

Please share the full screenshot of client script 

Amit Verma
Kilo Patron
Kilo Patron

Hi @Anjali yadav1 

 

Could you please elaborate a bit on your issue ? What do you mean by it is not working ?

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Deepak Shaerma
Kilo Sage
Kilo Sage

Hi @Anjali yadav1 
please elaborate your requirement, why you want to use cell edit script. This helps in clear understanding. 
Keep Learning

Regards,

Deepak Sharma

Ranjit Nimbalka
Mega Sage

Hi @Anjali yadav1 

 

please try below script that will work for you.

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
    var saveAndClose = true;
    var isAdmin = g_user.hasRole('admin');
   
    if ((isAdmin == false && newValue == 2) || (isAdmin == false && newValue == 3)) {
        alert("Not allowed to set this state");
        saveAndClose = false;
    }

    callback(saveAndClose);
}
Screenshot (6).png
 
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Ranjit