SetReadonly is not working for choices fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2023 03:58 AM
I have created one onload client script for impact and choice fields in incident form but it is not working
Onload :
Function onLoad () {
g_form. SetReadOnly ("impact", true) ;
g_form. SetReadOnly ("urgency ", true) ;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2023 09:12 AM
Yes but my requirement is based on role so I am write the client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2023 09:24 AM
Try:
g_form.setReadOnly('impact', g_user.hasRole('desired_role'));
g_form.setReadOnly('urgency', g_user.hasRole('desired_role'));
Similar client scripts have examples. Post your complete set of requirements, and folks here can assist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2023 09:28 AM
When user have the priority role then urgency and impact fields should be editable otherwise readonly for other users who didnot have priority role

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2023 10:04 AM
@siva44 Why don't you choose to create a write ACL on your table where the user with priority role can edit the records and for user not having priority role the field will become read only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2023 10:34 AM - edited 09-17-2023 12:01 PM
Hi Siva44,
Try something like:
if ((g_user.hasRoleFromList('sn_vul_container.vulnerability_admin', 'sn_vul_container.vulnerability_analyst', 'sn_vulc.admin', 'sn_vulc.vulnerability_analyst') && !g_user.hasRoleFromList('sn_vul.vulnerability_admin', 'sn_vul.vulnerability_analyst') && g_user.hasRole('sn_vul.app_sec_manager')) || (g_user.hasRoleExactly('sn_vul.app_sec_manager') && !g_user.hasRoleFromList('sn_vul.vulnerability_admin', 'sn_vul.vulnerability_analyst', 'sn_vul_container.vulnerability_admin', 'sn_vul_container.vulnerability_analyst', 'sn_vulc.admin', 'sn_vulc.vulnerability_analyst'))) {
g_form.setReadOnly('impact', [true/false]);
g_form.setReadOnly('urgency', [true/false]);
}
replace the role list with whatever roles you like. (Taken from OOB "Make Condition Mandatory on Load" client script). You should really look at existing examples in your instance.
Here's another one "Internal user readonly for non-agents"
function onLoad() {
if(!g_user.hasRoleFromList("sn_esm_agent, sn_esm_location_agent, sn_customerservice.relationship_agent")) {
// for users with no roles from the above list
g_form.setReadOnly('impact', true);
g_form.setReadOnly('urgency', true);
}
}