CSM Workspace – Modal popup validation not stopping submit (UI Page + UI Builder approach)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi everyone,
I am working on a requirement in CSM Workspace where I need to implement a modal popup that contains:
- Notes (mandatory)
- Date/Time (mandatory, should not allow past date)
On clicking a button from the Case form:
- A modal popup opens
- User fills both fields
- On Submit → values should update fields on the Case record
Current Approach (UI Action + UI Page + Glide Ajax)
- Workspace UI Action → opens modal using "g_model.showframe"
- UI Page contains form (text area + datetime)
- Client script performs validation
- Script Include updates the case record
Issue
Validation is working (error message shows), but:
The modal still closes even when validation fails
Expected Behavior
- If fields are empty → modal should NOT close
- If date is in past → modal should NOT close
- Modal should only close after successful save
What I tried
- Using "return false" in submit function
- Controlling button behavior
- Handling validation before GlideAjax call
Still seeing inconsistent modal behavior in Workspace.
Sharing the full code base -
UI action-
function onClick(g_form) {
var sysId = g_form.getUniqueValue();
g_modal.showFrame({
title: "Enter Information for Manual ORT",
url: "/sn_customerservice_openmanualort_InfoDialog.do?sysparm_sys_id=" + sysId,
type: "page",
size: "lg",
height: "280px"
});
}
UI Page-
HTML
Questions
- Is using UI Page + g_modal the correct approach in Workspace?
- How can we properly stop modal from closing on validation failure?
- Is there a recommended way to implement this using UI Builder (Modal component + data resource)?
Any guidance or best practices would be really helpful.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Here's the revised response without code:
Hi,
Thanks for sharing the full code, it makes it much easier to give useful feedback. Let me work through your questions and flag a few things I spotted in the implementation itself.
Before answering the questions, a couple of things worth checking in your current code
Looking at your submitDialog() function, there is a logic issue worth investigating. When validateORTDate() returns false, the code hides the submit button but does not return early, meaning execution continues and the GlideAjax call fires regardless of the validation result. Adding an early return after the failed date validation check should prevent the Ajax call from proceeding when validation has not passed.
Also worth checking: your buttons are inside a g:ui_form Jelly tag. This tag can trigger native HTML form submission behaviour that bypasses the return value from your JavaScript function entirely. If you do not need g:ui_form for anything else on the page (GlideAjax does not require it), removing it and ensuring your buttons explicitly use type="button" is likely to give you more predictable control over submission behaviour.
1. Is UI Page + g_modal.showFrame the right approach for Workspace?
It is supported, but generally considered a compatibility or migration pattern rather than the recommended approach for net-new Workspace functionality. The modal lifecycle in Workspace is influenced by iframe state and internal runtime events, not purely by your client-side logic, which is why behaviour can appear inconsistent even when your validation is firing correctly.
2. How can you reliably stop the modal closing on validation failure?
With showFrame, there is no fully guaranteed way to control modal closure from within the UI Page. Even with correct validation logic, the modal can close due to iframe navigation, form handling, or Workspace runtime events outside your control. Addressing the two points above may improve your current behaviour, but complete reliability is not always achievable with this pattern.
3. Is there a recommended Workspace-native approach?
Yes. For Workspace, the recommended approach is to use a UI Builder modal opened via a Declarative Action. This avoids the iframe entirely and gives you direct control over validation, submission, and modal lifecycle in a way that aligns with how Workspace is designed to operate. ServiceNow's documentation on Declarative Actions and UI Builder components on docs.servicenow.com is a good starting point if you want to explore that route.
One important caveat
I can only see the code shared here. There may be other factors in your implementation I am not aware of, including other client scripts or UI policies running in the workspace, declarative action mappings, global scripts, or workspace runtime configuration. Any of these could be contributing to the behaviour you are seeing, so it is worth reviewing those areas if the above does not fully resolve things.
Hope this helps move things forward. If it does, please mark it as helpful or accept it as the answer so it helps others in the community find useful answers more quickly.
