Catalog Client Script in a Variable Set: setReadOnly not working

tahnalos
Kilo Sage

I'm trying to use a Catalog Client Script to set Read Only to a bunch of variables in a variable set.  Others are having setReadOnly set to false as I expect data to be populated on these variables.  This variable set is on a Record Producer, and the script is only being run on the Target Record.

 

However, when I attempt to use g_fom.setReadOnly (<variable_name>, true) or g_form.setReadOnly (<variable_name>, false), neither of these options work.  And before you wonder why I'm using a Catalog Client Script instead of a Catalog UI policy, it's because I'm using a g_scratchpad variable to determine the course of action.

 

Is it possible that setReadOnly doesn't work on Catalog Client Scripts on variable sets?

 

Thanks

7 REPLIES 7

I will clarify as to what's happening.

 

This variable set is attached to a Record Producer.  It is only set to be enabled when the target of the Record Producer (in this instance, a Workplace Case) is loaded.  By default the variables in the Variable set are hidden. 

 

The catalog client script has two objectives: to unhide the fields in the variable set, and (depending on the value of the scratchpad variable, make some fields read only and others editable.  Here is an excerpt of the code:

 

function onLoad()
{
    g_form.setVisible (<field_name>, true);
    if (g_scratchpad.scratch_variable == value1)
    {  
        g_form.setReadOnly (<field_name>, true);
    }
    else if (g_scratchpad.scratch_variable == value2)
    {
        g_form.setReadOnly (<field_name>, false);
    }
}
 
There is no prefix for the field_name of the Variable so I need to know if the nomenclature for the SetVisible and SetReadOnly methods are correct.  Because right now, both of them are not working properly.  Again the if structure containing the scratchpad variable is working perfectly as I had tested out the variable itself and I can confirm that the data in the scratchpad variable is correct.

Ankur Bawiskar
Tera Patron
Tera Patron

@tahnalos 

if you are using display business to store scratchpad variable and trying to use that in catalog client script, then I believe scratchpad variable doesn't work in catalog client script

But only in normal client script.

Move your business rule logic to GlideAjax and use in catalog client script and use script include

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

tahnalos
Kilo Sage

 I can confirm the scratchpad variable is working.  It's gathering data as it should and it's going into the correct piece of code.  What is NOT working is the setReadOnly function.