KingC
Tera Contributor

Regarding OOTB Capability:
Based on current ServiceNow documentation, there is NO out-of-the-box method to programmatically retrieve the list of visible form fields during UI Action execution in Workspace. The recommended approaches are:
Approach 1: DOM Inspection (Most Dynamic)
Use client-side JavaScript to inspect the rendered form and extract field names from data attributes on form elements.
Pros: Accurately reflects runtime visibilityCons: Fragile if DOM structure changes; requires careful selector management
Approach 2: Workspace Declarative Actions with Payload
Configure the declarative action to pass form context. Limited by what Workspace exposes in the action payload.
Pros: Supported approach using framework capabilitiesCons: May not include all needed field metadata
Approach 3: Form Section/View Configuration Query
Query sys_ui_section and sys_ui_element for the form view being used.
Pros: Server-side approach; stableCons: Does not account for UI Policy or Client Script conditional visibility
Recommended Best Practice:
Implement a hybrid solution combining DOM inspection for accuracy with server-side validation for security. Encapsulate the logic in reusable components that can be updated if ServiceNow provides better APIs in future releases.

RELATED DOCUMENTATION REFERENCES
• ServiceNow Docs: UI Actions for Workspace
• ServiceNow Docs: Now Experience UI Framework
• ServiceNow Docs: GlideAjax
• ServiceNow Community: Workspace Customization Best Practices
• ServiceNow Developer Blog: Working with UI Builder Forms