set variables read only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 05:45 AM
Hi.
I want the variables in the picture below to be read only, but only on the specific "SCTASK" where the short description is: "Deliver computer to..." Those variables are from the "SC_ CAT_ITEM" although you see them on the "SCTASK".
I tried a ui policy with a script but it did not succeed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 05:50 AM - edited 12-27-2022 05:50 AM
Hi @Yuval Lanton ,
You can make use of onLoad client script on sc_task as below
function onLoad() {
//Type appropriate comment here, and begin script below
// Get the short description field value
var shortDescription = g_form.getValue('short_description');
// Check if the short description is "Deliver computer to..."
if (shortDescription == "Deliver computer to...") {
// Set the variables to read-only
g_form.setReadOnly('variable_1', true);
g_form.setReadOnly('variable_2', true);
// Add additional lines to set the read-only status of other variables as needed
}
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 06:20 AM
HI Gunjan. The script doesn't work.. The variables become 'read only', only after the state changes to "closed complete". I want it to be 'read only' regardless of the state's value...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 06:01 AM
What is in your UI Policy? The code you need is
g_form.setVariablesReadOnly(true);
You are probably better off with a onLoad Client Script. There are even out of the box client scripts for this which you can activate for the sc_req_item and sc_task tables, called 'Variable Editor Readonly', however they have no conditions. Therefore creating your own onLoad client script might be the best option, though technically I don't see why a UI policy wouldn't work the same way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 06:06 AM
Hi @Yuval Lanton,
As @Gunjan Kiratkar @ and@Laszlo Balla mentioned, You can write UI policy on sc_task table.
Check the short_description value is required value or not. the set all variables read only using
g_form.setVariablesReadOnly(true);
Thanks,
Sagar Pagar