$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
ServiceNowbeginnerNew

ServiceNow Client Script

Share

Write client scripts for form manipulation (onChange, onLoad, onSubmit)

Works with OpenClaude

You are a ServiceNow platform developer. The user wants to write client scripts that manipulate forms using onChange, onLoad, and onSubmit events.

What to check first

  • Verify you're in the correct ServiceNow instance and have access to the table where you'll create the client script
  • Check that the form you're targeting exists by navigating to the table module and opening a record
  • Confirm the field names you plan to manipulate by inspecting the form or checking the table schema (Settings > Fields & Columns)

Steps

  1. Navigate to System Definition > Client Scripts in your ServiceNow instance
  2. Click New to create a client script record
  3. Fill in the Table field with the target table name (e.g., incident, change_request)
  4. Set the UI Type to Desktop (or Mobile if needed)
  5. Choose the Type dropdown and select one of: onLoad, onChange, onSubmit
  6. Enter the target Field name if using onChange; leave blank for onLoad/onSubmit
  7. Write your script logic in the Script field using the g_form API object
  8. Check Active to enable the script immediately
  9. Click Submit to save; test by loading or interacting with the form

Code

// CLIENT SCRIPT - onLoad Example
function onLoad() {
  // Get current user info
  var currentUser = g_user.getID();
  var userName = g_user.getName();
  
  // Set field values on form load
  g_form.setValue('assigned_to', currentUser);
  
  // Show/hide fields based on conditions
  if (g_form.getValue('priority') === '1') {
    g_form.setVisible('escalation_reason', true);
  } else {
    g_form.setVisible('escalation_reason', false);
  }
  
  // Make field mandatory
  g_form.setMandatory('urgency', true);
  
  // Disable field
  g_form.setDisabled('state', true);
}

// CLIENT SCRIPT - onChange Example
function onChange(control, oldValue, newValue, isLoading) {
  // Only execute if form is fully loaded (not during initial load)
  if (isLoading) {
    return;
  }
  
  // Trigger when 'category' field changes
  if (control.getName() === 'category') {
    // Update dependent field
    if (newValue === 'hardware') {
      g_form.setValue('subcategory', '');
      g_form.setMandatory('asset_tag', true);
      g_form.setLabel('asset_tag', 'Asset Tag (Required)');
    } else if (newValue === 'software') {
      g_form.setMandatory('asset_tag', false);
      g_form.setLabel('asset_tag', 'Asset Tag');

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryServiceNow
Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
servicenowclient-scriptui

Install command:

curl -o ~/.claude/skills/snow-client-script.md https://clskills.in/skills/servicenow/snow-client-script.md

Related ServiceNow Skills

Other Claude Code skills in the same category — free to download.

Want a ServiceNow skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.