Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

set variables read only

Yuval Lanton
Tera Contributor

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.Screenshot (30).png

4 REPLIES 4

Gunjan Kiratkar
Kilo Patron
Kilo Patron

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

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...

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

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.

Sagar Pagar
Tera Patron

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

The world works with ServiceNow