askill
servicenow-client-scripts

servicenow-client-scriptsSafety 90Repository

Implement browser-side client scripts with GlideAjax patterns, UI Policies, and g_form APIs. Covers performance optimization, preventing browser blocking, and safe DOM access. Use for OnChange/OnLoad/OnSubmit scripts, UI Policies, and client-side field validation.

3 stars
1.2k downloads
Updated 2/28/2026

Package Files

Loading files...
SKILL.md

ServiceNow Client Scripting

Quick start

GlideAjax pattern (async, non-blocking):

function makeServerCall() {
    // Always check if already loading
    if (isLoading || g_form.getValue('field') === '') {
        return;
    }
    
    var ga = new GlideAjax('ScriptIncludeName'); // PascalCase
    ga.addParam('sysparm_name', 'methodName');
    ga.addParam('sysparm_data', g_form.getValue('source_field'));
    
    // MUST use getXMLAnswer (async), NEVER getXMLWait
    ga.getXMLAnswer(function(answer) {
        if (answer) {
            g_form.setValue('target_field', answer);
        }
    });
}

Critical rules

RuleReason
NO GlideRecordBlocks browser; use GlideAjax
Use getXMLAnswerAsync; prevents UI freeze
NO getXMLWaitForbidden; blocks browser
NO document/jQueryBreaks on Polaris/Next Experience
Use g_form APISafe across all versions

Performance optimization

Use g_scratchpad (server → client on load):

// Display Business Rule (server):
g_scratchpad.vip = true;

// OnLoad script (client):
if (g_scratchpad.vip) {
    g_form.setLabel('priority', 'VIP Priority');
}

Avoid redundant calls:

// ✓ CORRECT: Check client logic first
if (!isLoading && newValue) {
    // Make server call
}

// Set display value to avoid round-trips
g_form.setValue('ref_field', id, displayValue);

Best practices

  • Use UI Policies for visibility/mandatory/read-only logic
  • Always check isLoading flag before GlideAjax calls
  • Use setValue(field, id, display) to avoid extra queries
  • Avoid global variables; scope to specific tables
  • Test with all form layouts before production

Key APIs

APIPurpose
GlideAjaxAsync server communication
g_formForm field manipulation
g_scratchpadServer-to-client data passing
g_userCurrent user context
GlideRecordNEVER use client-side (blocks browser)
GlideModalDisplay modal dialogs

Reference

For GlideAjax templates, g_scratchpad patterns, and examples, see BEST_PRACTICES.md

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

83/100Analyzed 2/20/2026

High-quality technical skill for ServiceNow client scripting with strong safety guidance, clear code patterns, and good structure. Covers GlideAjax patterns, performance optimization, and critical anti-patterns. Well-organized with tables, code examples, and best practices. Slight deduction for completeness (missing UI Policy details) but overall excellent reference skill.

90
85
80
78
85

Metadata

Licenseunknown
Version-
Updated2/28/2026
PublisherDanielMadsenDK

Tags

apitesting