AutoSkill 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.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/servicenow-catalog-client-script-for-async-server-validation" ~/.claude/skills/ecnu-icalk-autoskill-servicenow-catalog-client-script-for-async-server-validatio && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/servicenow-catalog-client-script-for-async-server-validation/SKILL.mdsource content
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
- Trigger: The script must run on
.onSubmit - Input: Identify the reference variable (e.g.,
) referring toselect_server
.cmdb_ci_server - Async Check:
- Use
to fetch the server record and get itsg_form.getReference
.ip_address - Use
to call a server-side Script Include (e.g.,GlideAjax
).CheckOpStatus - Pass the
to the Script Include.ip_address
- Use
- Server-Side Logic (Context): The Script Include queries
for parent records wherecmdb_rel_ci
matches the input IP and checks if `operational_status == '1'.child.ip_address - 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.
- If operational servers are found:
- Asynchronous Submission Control:
- Because
is asynchronous, the initialGlideAjax
must returnonSubmit
to block submission while waiting.false - Use a mechanism (e.g.,
or global flags) to persist the validation state across the callback.sessionStorage - If validation passes (no operational servers), programmatically trigger
org_form.submit()
within the callback.g_form.save() - Ensure flags are cleared after submission to prevent loops.
- Because
Anti-Patterns
- Do not use synchronous
as it blocks the browser.getXMLWait() - 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
- User clicks Submit.
- Script checks if server is selected. If not, allow submit.
- If selected, initiate GlideAjax call and return
.false - 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