Block form submission based on an async GlideAjax validation without a hidden Yes/No field. Is there
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11m ago
Hi everyone,
I'm validating a shipping postal code against country-specific rules (stored as JSON in a system property) using a client-callable Script Include and GlideAjax. The validation should apply only when the `region` is NA or EMEA.
**Current approach**
- An **onChange** client script on `country1` (reference to `cmn_location`) and `postal_code1` calls the Script Include through GlideAjax. It shows the expected format as an info message and an error message if the code is invalid.
- Because the GlideAjax call is asynchronous, the onChange script stores the result in a dedicated field, `postal_validated` (Yes = invalid, No = valid).
- An **onSubmit** client script checks that field and returns `false` with an error message when it is "Yes".
**The concern**
I'd like to avoid creating and maintaining an extra field just to carry a validation result between onChange and onSubmit. It adds a field to the form or table, and it can be stale if the user submits before the async call returns. It also isn't set on form load for prefilled values.
**What I'm looking for**
1. Is there a recommended way to block submission based on a server-side validation **without a field to store the result**?
2. Would an onSubmit script that returns `false`, runs the GlideAjax call itself, and then calls `g_form.submit()` in the callback be reliable? How do you prevent a re-validation loop, for example with a client-side flag variable?
3. If this should work in both the native UI and Service Portal, is there a better option than the deprecated synchronous `getXMLWait()`, which isn't supported in Service Portal?
4. Is a server-side check (a Before Insert/Update business rule, or a data policy that aborts with an error message) a better place for the final enforcement, with the client script only giving early feedback?
5. If you've solved this differently, for example with a UI policy, a catalog variable validation, or a Script Include-only approach, I'd appreciate hearing it.
**Environment**
- Instance version: Zurich
- Form type: Catalog item
- UI: Service Portal
- Script Include scope: HAM scope
Thanks in advance for any guidance or examples.
Prithvi Ramesh
0 REPLIES 0