Snu form automation

From arnoudkooi/sn-scriptsync · View interactive version

Snu form automation is an AI agent skill from the GitHub repository arnoudkooi/sn-scriptsync. Drive live ServiceNow forms via the g_form bridge (navigate, set_field, get_form_state, run_ui_action, click_element): insert vs update verbs, optimistic-write verification, auto-handled native dialogs, and auto-filling mandatory reference fields. Read this when automating or visually verifying a fo

How to use this skill

Skill file

<!-- SN-SCRIPTSYNC:SKILL instructionsSchemaVersion=39 -->

SN ScriptSync β€” Live Form Automation

How to control and verify live ServiceNow forms through the authenticated browser session.

πŸ€– Live Form Automation & Visual Verification

Fill test data with `/rnd`

Use run_slash_command with /rnd for empty mandatory fields or /rnd -a for all empty editable fields. UI16 and Service Portal are Free; Configurable Workspace requires Pro, Enterprise or an active Pro trial. Workspace follows the active record tab and cancels pending fills if that form changes. A blocked Workspace fill returns E_PRO_REQUIRED before any fields are written. Inspect the completion summary and leave saving as a separate action. See the snu-agent-api skill for the response contract.

πŸ“Έ Verify visually EARLY β€” don't loop blind

doesn't behave as expected, take a screenshot to confirm the real page state instead of

iterating blindly through more API calls.

speculative attempts β€” a mandatory-field validation banner, a 404 "page not found", an

unsaved-changes state, or simply the wrong browser tab.

screenshot + read the page before a third attempt.**

Save verbs: insert (new) vs update (existing)

Use the correct UI action for the record's state β€” the wrong one silently no-ops:

| Record state | run_ui_action verb | Form button |

|--------------|----------------------|-------------|

| New (sys_id=-1) | sysverb_insert | "Submit" |

| Existing | sysverb_update | "Update" / "Save" |

Calling sysverb_update on a new record returns { "triggered": true } but inserts

nothing.

Live-form commands are optimistic β€” always verify server-side

set_field, run_ui_action, and click_element report what was *sent / triggered /

clicked* in the browser, not what committed. triggered: true means the UI action fired,

NOT that the save succeeded β€” a mandatory field or client/UI-policy validation can still

block it. Never report success on triggered: true alone.

Confirm the write before reporting success:

required after a new-record insert, or

activity stream, is proof of an insert).

Two traps that look like success but aren't:

record** (ServiceNow assigns these client-side at form load). The form having a

sys_id/number is NOT proof the record persisted.

mandatory fields (shown yellow on the form) are not flagged β€” screenshot before saving to

catch them.

Native dialogs are auto-handled (no hang)

Browser-native confirm() / alert() / prompt() and the dirty-form "Leave site?"

(beforeunload) prompt would otherwise freeze the tab and hang the bridge with no user to

click them. The live-form commands neutralize these automatically:

swallowed (suppressDialogs: true by default).

(discardUnsaved: true by default).

Two consequences to be deliberate about:

deleted. To prevent surprise deletes this verb is gated**: it returns E_DISABLED unless

sn-scriptsync.deleteRecords.enabled is on. Prefer delete_record (REST) for removals; it

never raises a dialog.

run_ui_action if you need to keep them, or pass discardUnsaved: false.

Recommended new-record cycle

navigate  (table.do?sys_id=-1)
β†’ set_field        (all mandatory + content fields)
β†’ take_screenshot  (confirm filled; catch yellow UI-policy-mandatory fields)
β†’ run_ui_action    sysverb_insert
β†’ query_records    (verify the record actually exists)   ← REQUIRED
β†’ report result

For an existing record the flow is the same but with sysverb_update and a

get_record / get_form_state verification. Prefer set_field (fires client scripts / UI

policies) over a raw REST update_record when you need the form's client logic to run. If a

save didn't persist, screenshot to read the validation banner, fill the missing fields, and

retry once.

Auto-fill mandatory REFERENCE fields (no hardcoded sys_ids)

  1. get_table_metadata(formTable) β†’ find columns with type=reference and their reference

table (this resolves table inheritance for you).

  1. For each mandatory reference column: get_parent_options(referenceTable) β†’ take an

option.sys_id (prefer active=true; mind reference qualifiers).

  1. set_field(column, sys_id).

β†’ reference table, then query_records(refTable, …, limit 1).

name=<child> β€” query across the whole table hierarchy.

Commands

`navigate` ⚑ (Remote - Async)

Navigate a connected ServiceNow tab to a URL (opening a tab if none is found) and resolve once the page finishes loading. Use this to put a specific record/list in front of the live-form commands (set_field, get_form_state, run_ui_action). For a screenshot in the same step, prefer navigate_and_screenshot.

Request:

{
  "id": "nav_1",
  "command": "navigate",
  "params": { "url": "https://dev12345.service-now.com/incident.do?sys_id=-1" }
}

Parameters:

Response (success):

{
  "id": "nav_1",
  "command": "navigate",
  "status": "success",
  "timestamp": 1733779200000,
  "result": {
    "navigated": true,
    "tabId": 12345,
    "url": "https://dev12345.service-now.com/incident.do?sys_id=-1",
    "title": "Incident | ServiceNow"
  }
}

Response (error):

{
  "id": "nav_1",
  "command": "navigate",
  "status": "error",
  "code": "E_INVALID_PARAMS",
  "error": "Only http(s) URLs are allowed"
}

Error codes: E_INVALID_PARAMS (missing/invalid URL), E_NO_TAB (could not activate/open a tab), E_BROWSER_DISCONNECTED, E_TIMEOUT.

`set_field` ⚑ (Remote - Async)

Set a field value on the active ServiceNow form in the connected browser tab via g_form.setValue. Because this drives the live form, it fires client scripts, onChange handlers, and UI policies β€” unlike a REST update_record, which bypasses all client-side logic. Use it to reproduce/verify client behaviour, not for bulk data writes.

Request:

{
  "id": "sf_1",
  "command": "set_field",
  "params": {
    "field": "short_description",
    "value": "Network down in building C"
  }
}

Parameters:

Response (success):

{
  "id": "sf_1",
  "command": "set_field",
  "status": "success",
  "timestamp": 1733779200000,
  "result": {
    "set": true,
    "field": "short_description",
    "value": "Network down in building C",
    "displayValue": "Network down in building C"
  }
}

Response (error):

{
  "id": "sf_1",
  "command": "set_field",
  "status": "error",
  "code": "E_NO_FORM",
  "error": "No active form on this page"
}

Error codes: E_INVALID_PARAMS (missing field/value), E_NO_FORM (no g_form on the page), E_NOT_FOUND (field not on the form), E_BROWSER_DISCONNECTED, E_TIMEOUT.

Tip: Run get_form_state after set_field to confirm the value (and any dependent fields recalculated by client logic) before triggering a save.

`get_form_state` ⚑ (Remote - Async)

Read the live form in the connected browser tab: its table, sys_id, new-record flag, and current field values (including unsaved edits). Reads from g_form, so it reflects what the user/agent actually sees β€” not the saved database row. Pair it with set_field to verify writes and with /tn (run_slash_command) when you need technical field names.

Request (all fields):

{
  "id": "gfs_1",
  "command": "get_form_state"
}

Request (subset):

{
  "id": "gfs_2",
  "command": "get_form_state",
  "params": { "fields": ["state", "assigned_to", "short_description"] }
}

Parameters:

Response (success):

{
  "id": "gfs_2",
  "command": "get_form_state",
  "status": "success",
  "timestamp": 1733779200000,
  "result": {
    "table": "incident",
    "sys_id": "a1b2c3...",
    "isNewRecord": false,
    "fields": {
      "state": { "value": "2", "displayValue": "In Progress", "mandatory": false, "readOnly": false },
      "assigned_to": { "value": "62826bf0...", "displayValue": "Beth Anglin" },
      "short_description": { "value": "Network down", "displayValue": "Network down" }
    }
  }
}

Response (error):

{
  "id": "gfs_1",
  "command": "get_form_state",
  "status": "error",
  "code": "E_NO_FORM",
  "error": "No active form on this page"
}

Error codes: E_NO_FORM (no g_form on the page), E_BROWSER_DISCONNECTED, E_TIMEOUT.

`run_ui_action` ⚑ (Remote - Async)

Trigger a UI action on the active ServiceNow form in the connected browser tab. Runs the real client-side path (g_form.save() / g_form.submit()), so onSubmit client scripts and UI policies execute. A page reload usually follows, so the command resolves as soon as the action is dispatched (not when the reload finishes) β€” re-read with get_form_state afterward.

Request:

{
  "id": "rua_1",
  "command": "run_ui_action",
  "params": { "uiAction": "save" }
}

Parameters:

⚠️ Pick the verb that matches the record state: use sysverb_insert ("Submit") on a new record (sys_id=-1) and sysverb_update ("Update"/"Save") on an existing one. Calling sysverb_update on a new record returns { "triggered": true } but inserts nothing.

πŸ”’ Every verb is gated: committing the open form writes a record, so run_ui_action requires the updateRecords permission (sn-scriptsync.updateRecords.enabled, SNU_ALLOW_UPDATE_RECORDS, or the per-instance grant; on by default, following createArtifacts where it is not set on its own). A custom action's name says nothing about what it does, so the gate applies to all of them rather than only the ones that look like writes.

πŸ”’ Destructive verbs escalate: any delete verb (sysverb_delete, or a custom action whose name contains delete) is rejected with E_DISABLED unless sn-scriptsync.deleteRecords.enabled is on β€” the same guard that protects delete_record, and it is not satisfied by updateRecords. Prefer delete_record for removals; it never raises a dialog.

Response (success):

{
  "id": "rua_1",
  "command": "run_ui_action",
  "status": "success",
  "timestamp": 1733779200000,
  "result": { "triggered": true, "uiAction": "save" }
}

Response (error):

{
  "id": "rua_1",
  "command": "run_ui_action",
  "status": "error",
  "code": "E_NO_FORM",
  "error": "No active form on this page"
}

Error codes: E_NO_FORM (no g_form on the page), E_DISABLED (the updateRecords gate is off, or a delete verb while deleteRecords.enabled is off), E_BROWSER_DISCONNECTED, E_TIMEOUT.

Note: success confirms the action was dispatched, not that the save succeeded server-side. If a mandatory field or an onSubmit script blocks the save, the form stays open β€” verify with a follow-up get_form_state or a take_screenshot.

`click_element` ⚑ (Remote - Async)

Click a DOM element by CSS selector in the ServiceNow content document of the connected tab. Best-effort and light-DOM only β€” it does not pierce shadow DOM (Polaris/Next Experience web components). For form fields and UI actions prefer set_field / run_ui_action; reach for click_element only when there is no g_form path (e.g. a classic UI button or link).

Request:

{
  "id": "ce_1",
  "command": "click_element",
  "params": { "selector": "#sysverb_update" }
}

Parameters:

Response (success):

{
  "id": "ce_1",
  "command": "click_element",
  "status": "success",
  "timestamp": 1733779200000,
  "result": { "clicked": true, "selector": "#sysverb_update" }
}

Response (error):

{
  "id": "ce_1",
  "command": "click_element",
  "status": "error",
  "code": "E_NOT_FOUND",
  "error": "Element not found: #sysverb_update"
}

Error codes: E_INVALID_PARAMS (missing/invalid selector), E_NOT_FOUND (no element matches), E_BROWSER_DISCONNECTED, E_TIMEOUT.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.