UI policy

yaddanki
Tera Contributor

I want to make a field read only for non admin roles on incident form. 
Can any one explain step by step procedure and if script required please help me with that.

2 ACCEPTED SOLUTIONS

J Siva
Tera Sage

Hi @yaddanki 
You need to craete "On load" client script to acheive this.
PFB sample. to make the date field read-only for non-admin users.
Client script:

JSiva_0-1745208111747.png

function onLoad() {
    if (!g_user.hasRole('admin')) {
        g_form.setReadOnly('<FIELD NAME>', true); //REPLACE THE <FIELD NAME> WITH THE ACTUAL FIELD
    } else {
        g_form.setReadOnly('<FIELD NAME>', false); //REPLACE THE <FIELD NAME> WITH THE ACTUAL FIELD
    }

}

Non-Admin user view:

JSiva_1-1745208189676.png

Admin user view:

JSiva_2-1745208228922.png

Hope this helps.
Regards,
Siva

 

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@yaddanki 

2 approaches

1) simply create a field level WRITE ACL

Give "admin" in roles section

OR

2) you cannot use UI policy for this, please use onLoad client script on incident table

function onLoad() {

    if (!g_user.hasRoleExactly('admin')) {
        g_form.setReadOnly('fieldName', true);
    }
}

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

2 REPLIES 2

J Siva
Tera Sage

Hi @yaddanki 
You need to craete "On load" client script to acheive this.
PFB sample. to make the date field read-only for non-admin users.
Client script:

JSiva_0-1745208111747.png

function onLoad() {
    if (!g_user.hasRole('admin')) {
        g_form.setReadOnly('<FIELD NAME>', true); //REPLACE THE <FIELD NAME> WITH THE ACTUAL FIELD
    } else {
        g_form.setReadOnly('<FIELD NAME>', false); //REPLACE THE <FIELD NAME> WITH THE ACTUAL FIELD
    }

}

Non-Admin user view:

JSiva_1-1745208189676.png

Admin user view:

JSiva_2-1745208228922.png

Hope this helps.
Regards,
Siva

 

Ankur Bawiskar
Tera Patron
Tera Patron

@yaddanki 

2 approaches

1) simply create a field level WRITE ACL

Give "admin" in roles section

OR

2) you cannot use UI policy for this, please use onLoad client script on incident table

function onLoad() {

    if (!g_user.hasRoleExactly('admin')) {
        g_form.setReadOnly('fieldName', true);
    }
}

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