Make few variables editable on sctask

Advaitk
Tera Contributor

Hi everyone,

I have created a Catalog Item that successfully generates a Request Item (RITM) and a Catalog Task (SCTASK) upon submission.

The requirement is to make specific variables editable on the SCTASK form, whereas they should remain read-only by default. To achieve this, I implemented a combination of a Display Business Rule (to pass data via g_scratchpad) and an onLoad Client Script to toggle the field permissions.

This solution works perfectly for System Administrators (the variables are editable). However, when I impersonate a standard user from the assignment group assigned to that task, all the variables remain strictly read-only.

Has anyone encountered this issue before, or can you point me toward what might be blocking this?

Thanks!

CC: @Ankur Bawiskar 

7 REPLIES 7

vaishali231
Kilo Sage

Hey @Advaitk 

For SCTASK variable editing, you need both:
Write ACL access
Client-side logic to remove read-only state
Solution
Create Write ACL
Table:
sc_item_variables_task
Operation:
write
Script:

answer = current.task.assignment_group &&
gs.getUser().isMemberOf(current.task.assignment_group);

This allows users from the task assignment group to update variables.
Display Business Rule on sc_task

(function executeRule(current, previous) {
g_scratchpad.canEdit =
gs.getUser().isMemberOf(current.assignment_group);

})(current, previous);

onLoad Client Script

function onLoad() {

if (g_scratchpad.canEdit || g_user.hasRole('admin')) {

g_form.setReadOnly('variables.variable_name_1', false);
g_form.setReadOnly('variables.variable_name_2', false);

}
}

Important Notes
Admin works because ACLs are bypassed automatically.
Without the sc_item_variables_task write ACL, non-admin users will always see variables as read-only.
Also verify that:
     Variable itself is not marked Read Only
     No Catalog UI Policy is forcing read-only
    No other Client Script is resetting the field state
One additional improvement:
In some cases, variable fields on SCTASK behave inconsistently with individual setReadOnly() calls. You can also try:

g_form.setVariablesReadOnly(false);

and then selectively make required variables read-only again if needed.


*************************************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb

 

 

 

 

 

 

 

 

 

 

Thanks for the response. I tried your solution but it is not working. Don't know why.

Thank you!

Venky Kshatriy2
Tera Contributor

Please use a catalog client script to specify where your UI policy should be applied. For reference, please follow the diagram provided below.(use read only false)

VenkyKshatriy2_0-1779096256198.png

this won't work fallow this one

Variables stay read-only for normal users because catalog variable write access is controlled by roles/ACLs (like sc_item_option_mtom), and only admins bypass this—so you must give proper Write roles to the variable or move editable data to SCTASK fields.
Spoiler
If my answer is correct, please mark it as solved so it can assist others as well.