- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 01:12 PM
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);
}
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2022 01:34 AM
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.
The script are the same as in the question.
Catalog and Requested Items Client Script
Catalog Tasks Client Script
Execution result:
Step1: Catalog item view. Only show common field
Step 2: Requested Items view. Only show common field
Step 3: Catalog Tasks view. All fields are displayed as mandatory

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 01:18 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 01:49 PM
The variable itself is not Mandatory. Are you referring to the Mandatory code in the script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 01:40 PM
Hi,
I would recommend that you create a Catalog UI policy instead. No scripting required.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2022 01:34 AM
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.
The script are the same as in the question.
Catalog and Requested Items Client Script
Catalog Tasks Client Script
Execution result:
Step1: Catalog item view. Only show common field
Step 2: Requested Items view. Only show common field
Step 3: Catalog Tasks view. All fields are displayed as mandatory