Variable Read Only

Bishal Sharma
Tera Contributor

Hi,

 

Can you help me to make below particular variable read only when state is closed complete or closed incomplete or closed skipped. (screenshot attached)

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi @Bishal Sharma 

This can be done using a Client Script on Catalog Task Table. You just need to write an On Change Client Script on Catalog Task Table on State Field and use the script below:

This client script will take care of both scenario when state changes also after you save the form it will validate for the state value to make it read only.

Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        var getState = g_form.getValue('state');
        if (getState == 3 || getState == 4 || getState == 7) {
            g_form.setReadOnly('variables.checkbox', true);
        }
        return;
    }
    if (newValue == 3 || newValue == 4 || newValue == 7) {
        g_form.setReadOnly('variables.checkbox', true);
    }

    //Type appropriate comment here, and begin script below

}

Screenshot for reference:

find_real_file.png

Result:

Script is an tested one in my PDI and will work for you as well for the query mentioned.

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

10 REPLIES 10

sachin_namjoshi
Kilo Patron
Kilo Patron

Configure a Catalog UI policy based on your condition.

 

https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/product/service-catalog-management/concept/c_ServiceCatalogUIPolicy.html#:~:text=UI%20policies%20can%20be%20used,applied%20to%20service%20catalog%20items.

 

Regards,

Sachin

Hi,

 

I can't see state field in condition. How am I supposed to apply filter.

 

Please see the screenshot

Do you want to do at requested item level or catalog task level?

In either scenario, you can always configure catalog client script and use g_form.setReadOnly(field, boolean) method make field read only based on state

 

Regards,

Sachin

I wrote below code:

 

function onSubmit() {

var statevalue = g_form.getValue('state');

if((statevalue == 7) || (statevalue == 4) || (statevalue == 3))
{
g_form.setReadOnly('Additional_software_requirements', true);
}


}

 

But after saving the form, the variables gets editable again. 

 

Any suggestions ?