The CreatorCon Call for Content is officially open! Get started here.

restrict the task state based on assigned to field

vinnus
Tera Contributor

we are making task state editable on below conditions only on top of we need add assigned to is current logged in user then only can edit the state field 

vinnus_0-1733154335567.png

action:

vinnus_1-1733154357276.png

 

 

 

tried wit run script  in true section not working and assigned to dynamic (me) as well

if (current.assigned_to == gs.getUserID()) {
    g_form.setReadOnly('state', false); // Make editable
} else {
    g_form.setReadOnly('state', true); // Make read-only
}
3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@vinnus 

current object works in server side but you are using UI policy

So update as this

if (g_form.getValue('assigned_to') == g_user.userID) {
g_form.setReadOnly('state', false); // Make editable
} else {
g_form.setReadOnly('state', true); // Make read-only
}

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

have tried but still Not working not sure where is UI policy conflict, can you please help me out. Thanks 

Sandeep Rajput
Tera Patron
Tera Patron

@vinnus You are mixing client and server side code here. current.assigned_to should be replaced with g_form.getValue('assigned_to')==g_user.userID;