hide the variables in a variable set for a particular catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
i have created a catalog item and added variables set to it, in this variable set i have variables which are mandatory at the dictionary level , but i want to hide this variables to the catalog item in which this variable set is added
can u help with this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Did you try using the Catalog UI Policy for the specific item?
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I doubt this will work since you made variable mandatory at variable config level
But still you can try to use onLoad catalog client script which applies to your catalog item and see if that works
-> make them mandatory false and then hide them
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
@ShaziyaS4380655 , Can you try creating a onload client script on service catalog and use below code to hide your mandatory field.
g_form.setDisplay('your_variable_name', false);
g_form.setValue('your_variable_name', 'default_value');
But keep in mind :
- You must set a value for mandatory fields even when hidden
- The value should be valid according to the field's type
- Test thoroughly to ensure the hidden mandatory field doesn't cause submission issues
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @ShaziyaS4380655 ,
To hide mandatory variables from a catalog item while keeping them in the variable set, you can achieve this by using Catalog Client Scripts or Catalog UI Policies in ServiceNow. Here's how you can do it:
Solution 1: Using a Catalog Client Script:
- Create a Catalog Client Script for the catalog item.
- Use the following script to hide the variables:
function onLoad() {
// Replace 'variable_name' with the actual name of the variable you want to hide
g_form.setDisplay('variable_name', false);
}
- This will hide the variable from the catalog item form while keeping it mandatory at the dictionary level.
Solution 2: Using a Catalog UI Policy:
- Create a Catalog UI Policy for the catalog item.
- Set the condition for when the variable should be hidden.
- In the UI Policy Actions, configure the following:
- Select the variable you want to hide.
- Set Visible to false.
This approach is more user-friendly and doesn't require scripting.
Important Notes:
- Even though the variable is hidden, it will still be mandatory at the dictionary level. If you want to bypass the mandatory check for hidden variables, you can use a Catalog Client Script to dynamically make it non-mandatory when hidden:
function onLoad() {
g_form.setMandatory('variable_name', false);
g_form.setDisplay('variable_name', false);
}
- Ensure that hiding the variable aligns with your business requirements, as mandatory fields are typically required for data integrity.
If you found my response helpful, could you please mark it as ‘Accept as Solution’ and ‘Helpful’? This small action goes a long way in helping other community members find the right answers more easily and supports the community.