Issue with Client Script not displaying variables

Sami Ahmed
Tera Contributor

We have an ask to hide certain variables on a catalog item for the catalog & requested item view. It should only show up on the task form view. as per previous recommendations, I have created two different client scripts. One to hide the variables applicable on the Catalog Item & Requested Item view. Another script to display the variables on the Task view. 

It works perfectly fine for all variables except one variable. I have recreated the variables and the scripts to see if there is a glitch that prevented it from being added but still not able to resolve this issue. 

Script to Show Variables

function onLoad() {

 g_form.setDisplay('variable1', true);

g_form.setMandatory('variable1', true);

 g_form.setDisplay('variable2', true);

g_form.setMandatory('variable2', true);

 g_form.setDisplay('variable3', true);

g_form.setMandatory('variable3', true);

 g_form.setDisplay('variable4', true);

g_form.setMandatory('variable4', true);

 g_form.setDisplay('variable5', true);

g_form.setMandatory('variable5', true);

 g_form.setDisplay('application_input', true);

g_form.setMandatory('application_input', true);

 g_form.setDisplay('application_input_type_2', true);

g_form.setMandatory('application_input_type_2', true);

}

 

Script to Hide Variables

 

function onLoad() {

     g_form.setDisplay('variable1', false);

     g_form.setDisplay('variable2', false);

     g_form.setDisplay('variable3', false);

     g_form.setDisplay('variable4', false);

     g_form.setDisplay('variable5', false);

     g_form.setDisplay('application_input', false);

     g_form.setDisplay('application_input_type_2', false);

 

}

 

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Sami,

Tried the script and it worked OK on my instance.

Defined variables as follows. I've set Global to "true" on all variables so it'll be included in the Catalog Task form.

find_real_file.png

The script are the same as in the question.

Catalog and Requested Items Client Script

find_real_file.png

 Catalog Tasks Client Script

find_real_file.png

 Execution result:

Step1: Catalog item view. Only show common field

find_real_file.png

Step 2: Requested Items view. Only show common field

find_real_file.png

Step 3: Catalog Tasks view. All fields are displayed as mandatory

find_real_file.png

View solution in original post

5 REPLIES 5

asifnoor
Kilo Patron

Hi,

Before hiding the variables, set the Mandatory of the variable to false and then hide it and check.

Mark the comment as a correct answer and helpful if this has helped to solve the problem.

The variable itself is not Mandatory. Are you referring to the Mandatory code in the script? 

OlaN
Giga Sage
Giga Sage

Hi,

I would recommend that you create a Catalog UI policy instead. No scripting required.

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Sami,

Tried the script and it worked OK on my instance.

Defined variables as follows. I've set Global to "true" on all variables so it'll be included in the Catalog Task form.

find_real_file.png

The script are the same as in the question.

Catalog and Requested Items Client Script

find_real_file.png

 Catalog Tasks Client Script

find_real_file.png

 Execution result:

Step1: Catalog item view. Only show common field

find_real_file.png

Step 2: Requested Items view. Only show common field

find_real_file.png

Step 3: Catalog Tasks view. All fields are displayed as mandatory

find_real_file.png