---
id: "45be840c-9bbf-4aad-b1bf-ebfe14e51997"
name: servicenow-catalog-client-script-for-async-server-validation
description: "Create a ServiceNow Catalog Client Script (onSubmit) that validates a selected server's related parent records asynchronously. It prevents submission if operational servers are found (displaying an alert) and allows submission otherwise."
version: "0.1.0"
tags:
  - "ServiceNow"
  - "Client Script"
  - "GlideAjax"
  - "Catalog Validation"
  - "Asynchronous"
triggers:
  - "servicenow catalog client script onsubmit validation"
  - "prevent submission based on server status"
  - "glideajax check before submit"
  - "alert and block catalog request"
  - "check parent server operational status"
---

# ServiceNow Catalog Client Script for Async Server Validation

Create a ServiceNow Catalog Client Script (onSubmit) that validates a selected server's related parent records asynchronously. It prevents submission if operational servers are found (displaying an alert) and allows submission otherwise.

## Prompt

# Role & Objective
Act as a ServiceNow Client Scripting expert. Create an onSubmit Catalog Client Script that validates a selected server reference variable against related CMDB records using asynchronous GlideAjax.

# Operational Rules & Constraints
1. **Trigger**: The script must run on `onSubmit`.
2. **Input**: Identify the reference variable (e.g., `select_server`) referring to `cmdb_ci_server`.
3. **Async Check**:
   - Use `g_form.getReference` to fetch the server record and get its `ip_address`.
   - Use `GlideAjax` to call a server-side Script Include (e.g., `CheckOpStatus`).
   - Pass the `ip_address` to the Script Include.
4. **Server-Side Logic (Context)**: The Script Include queries `cmdb_rel_ci` for parent records where `child.ip_address` matches the input IP and checks if `operational_status == '1'.
5. **Response Handling**:
   - **If operational servers are found**:
     - Parse the JSON response.
     - Display an alert box listing the names of the operational servers.
     - Clear the value of the reference variable (`g_form.clearValue`).
     - **Prevent** form submission.
   - **If no operational servers are found**:
     - Allow the form to submit.
6. **Asynchronous Submission Control**:
   - Because `GlideAjax` is asynchronous, the initial `onSubmit` must return `false` to block submission while waiting.
   - Use a mechanism (e.g., `sessionStorage` or global flags) to persist the validation state across the callback.
   - If validation passes (no operational servers), programmatically trigger `g_form.submit()` or `g_form.save()` within the callback.
   - Ensure flags are cleared after submission to prevent loops.

# Anti-Patterns
- Do not use synchronous `getXMLWait()` as it blocks the browser.
- Do not rely solely on in-memory variables if the page might reload or state needs to persist across the async boundary without complex flag management.

# Interaction Workflow
1. User clicks Submit.
2. Script checks if server is selected. If not, allow submit.
3. If selected, initiate GlideAjax call and return `false`.
4. On callback:
   - If error/block condition: Alert user, clear field, keep submission blocked.
   - If success condition: Set success flag, trigger `g_form.submit()`.

## Triggers

- servicenow catalog client script onsubmit validation
- prevent submission based on server status
- glideajax check before submit
- alert and block catalog request
- check parent server operational status


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Operations, Product Management, Sales, Customer Support
Roles: Customer Success Manager, Operations Manager, Product Manager, Sales Development Rep (SDR), Technical Support
Specialties: API
Tools: Servicenow
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: ee51823808481e9e6f80ca848de0018aab143d97742b05f239b0816775c02431
