How to dynamically populate checkbox in a Service Catalog Item from a client-side JSON buffer

ManishS14752344
Tera Contributor
Context:
I am building an integration use case within a Service Catalog Item.
  1. The user enters a change request number (CR/CTR).
  2. An asynchronous GlideAjax script fetches matching records from an external ServiceNow instance table and stores the raw JSON payload in a hidden text variable acting as a local cache buffer (u_data_buffer).
  3. The catalog item filters this JSON buffer to populate unique Billing Account Numbers (BAN) into a native drop-down selection field.
The Requirement:
When a user selects a specific BAN, the form must display a list of all related MSS IDN codes (retrieved from the cached JSON buffer). Crucially, the customer needs to be able to select multiple MSS IDN values for that single BAN.
The Problem:
Since we are not referencing a live local table on our instance (the data lives strictly inside the client-side JSON buffer), we cannot use a standard List Collector variable.
I attempted to create a Container variable on the form containing multiple pre-allocated, generic Checkbox variables (e.g., u_mss_check_1, u_mss_check_2, etc.). My onChange script correctly loops through the filtered JSON records, sets the hidden checkboxes to visible (g_form.setDisplay(varName, true)), and scales down to the exact row count returned.
However, I cannot dynamically change the checkbox labels to display the actual MSS IDN text string.
What I have tried that didn't work:
  1. g_form.setLabelOf() – This fails because checkboxes are structural elements rather than typical inputs, and this native API does not change the label text of catalog checkboxes.
  2. DOM Manipulation & jQuery UI Overrides – Unchecking Isolate Script and attempting to target selectors like document.getElementById('label_' + ...), document.querySelector, or $j('label[for=...]') either completely fails to alter the text or errors out with TypeError: Cannot read properties of undefined in the Service Portal runtime workspace.
  3. Native HTML/Custom Macro Variables – Injecting raw checkbox template strings dynamically via .innerHTML directly into a custom widget macro container element.
  4. Standard Select Box (with 'Multiple' checked) – Browser native multi-select options aren't successfully capturing or updating the dynamic options cleanly in our current portal layout wrapper.
Question:
How can I cleanly achieve a multi-select choice list UI inside a Catalog Item where both the Choice Values and Choice Labels are generated purely dynamically on the fly from a client-side JSON string array? Is there a clean, upgrade-safe workaround to change Checkbox variable labels dynamically on the Service Portal, or should I structure this configuration differently?
1 REPLY 1

Ankur Bawiskar
Tera Patron

@ManishS14752344 

my thoughts

-> don't use native checkbox variable for this

-> use a custom widget to show the checkboxes

Share your current approach along with screenshots

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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