Variable Set fields in Classic Catalog not working(g_form.setDisplay() and g_form.setMandatory())
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 2 hours ago
Hello Everyone,
I am facing an issue with controlling Variable Set visibility and mandatory fields dynamically using Client Scripts in the Classic Catalog backend view.
I have a Catalog Item with a Variable Set called "Shipping Details"
Internal Name: shipping_address_reclaim_asset
Variable Names: first_name, last_name, street_address, apt_street_other, city, state_province, zip_postal_code.
I have a Script Include that checks if the logged-in user's company has "u_shipping_required = true" in a custom policy table (sn_hamp_territory_procurement). • Based on the result, I want to: → SHOW Variable Set + Make fields mandatory (if shipping required = true) → HIDE Variable Set + Remove mandatory (if shipping required = false)
✅ Script Include is returning correct response (true/false) ✅ GlideAjax call is working correctly ✅ STEP 6 alert fires confirming response = 'true' ✅ Everything works perfectly in ESC Portal ✅ g_form.setDisplay() works on regular catalog variables.
❌ g_form.setDisplay('shipping_address_reclaim_asset', false) → Variable Set still visible for ALL users in backend ❌ g_form.setMandatory('first_name', true) → Fields not showing mandatory (*) indicator in backend.
Script Include:
Client Scripts:
// OnLoad function onLoad()--> UI Type as All
Backend: Fields are not mandatory and variable set showing for all users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I hope UI type is set to ALL for that onLoad script
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
@Ankur Bawiskar UI type is ALL always, but it is not working.
That is thing i'm unable to figure it out and fix this issue.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
what debugging did you do for native?
alert came?
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago - last edited 54m ago
@Ankur Bawiskar I used some alerts to print whether it is making mandatory or not.
In the alerts it shows Mandatory false in backend view and Mandatory true in Front end view.
Script with alerts:
please let me know where it is wrong:
Thanks,
Sattar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6m ago
Hi @sattar3,
Begin the script as setting every possibility of mandatory variable to be false in this context, then set Display false, then do your checks.
Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.
Kind Regards,
Ehab Pilloor