Business Rule Patterns logo

Business Rule Patterns

Organization
serac-labs
business-rule-patterns

Write ServiceNow business rules (before/after/async/display) — current vs previous, changesTo/changesFrom, recursion avoidance, setAbortAction, and async dispatch for heavy work.

Overview

Publisherserac-labs
Repositoryserac
Skill namebusiness-rule-patterns
Stars
78
Forks
26
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by serac-labs on GitHub. Read the source before you install it.

Installation

Install the Business Rule Patterns AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/serac-labs/serac.git /tmp/serac
mkdir -p .claude/skills
cp -r /tmp/serac/packages/skills/business-rule-patterns .claude/skills/business-rule-patterns
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Business Rule Patterns in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Business Rule Patterns on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Business Rule Patterns is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Business Rule Best Practices for ServiceNow

Business Rules are server-side scripts that execute when records are displayed, inserted, updated, or deleted.

When to Use Each Type

TypeTimingUse CasePerformance Impact
BeforeBefore database writeValidate, modify current recordLow
AfterAfter database writeCreate related records, notificationsMedium
AsyncBackground (after commit)Heavy processing, integrationsNone (background)
DisplayWhen form loadsModify form display, set defaultsLow

Available Objects

javascript
// In Business Rules, these are always available:
current // The record being operated on
previous // The record BEFORE changes (update/delete only)
gs // GlideSystem utilities

Before Business Rules

Use for validation and field manipulation:

javascript
// Prevent update if condition not met
;(function executeRule(current, previous) {
  if (current.state == 7 && previous.state != 6) {
    current.setAbortAction(true)
    gs.addErrorMessage("Must resolve before closing")
  }
})(current, previous)
javascript
// Auto-populate fields
;(function executeRule(current, previous) {
  if (current.isNewRecord()) {
    current.setValue("caller_id", gs.getUserID())
    current.setValue("opened_by", gs.getUserID())
  }
})(current, previous)

Never do in Before rules:

  • Call current.update() (causes recursion!)
  • Query other tables (keep it fast)
  • External API calls

After Business Rules

Use for related record operations:

javascript
// Create child record when priority is P1
;(function executeRule(current, previous) {
  if (current.priority.changesTo(1)) {
    var task = new GlideRecord("task")
    task.initialize()
    task.setValue("short_description", "P1 Follow-up: " + current.number)
    task.setValue("parent", current.sys_id)
    task.insert()
  }
})(current, previous)
javascript
// Update parent record
;(function executeRule(current, previous) {
  var parent = new GlideRecord("problem")
  if (parent.get(current.problem_id)) {
    parent.setValue("related_incidents", parent.related_incidents + 1)
    parent.update()
  }
})(current, previous)

Async Business Rules

Use for heavy processing that shouldn't block the transaction:

javascript
// External integration
;(function executeRule(current, previous) {
  var integrator = new ExternalSystemIntegration()
  integrator.syncIncident(current.sys_id)
})(current, previous)
javascript
// Send custom notification
;(function executeRule(current, previous) {
  gs.eventQueue("incident.priority.high", current, current.assigned_to, gs.getUserID())
})(current, previous)

Useful Methods

current Methods

javascript
current.isNewRecord() // True if insert
current.isValidRecord() // True if record exists
current.getValue("field") // Get field value
current.setValue("field", val) // Set field value
current.setAbortAction(true) // Cancel the operation
current.operation() // 'insert', 'update', 'delete'
current.isActionAborted() // Check if aborted

Field Change Detection

javascript
current.priority.changes() // Field changed (any value)
current.priority.changesTo(1) // Changed TO this value
current.priority.changesFrom(3) // Changed FROM this value
current.priority.nil() // Field is empty

previous Comparisons

javascript
// Check if field was modified
if (current.state != previous.state) {
  gs.info("State changed from " + previous.state + " to " + current.state)
}

// Check specific change
if (current.assigned_to.changes() && !previous.assigned_to.nil()) {
  gs.info("Reassignment occurred")
}

Condition Examples

Use conditions to limit when the rule runs:

ConditionMeaning
current.active == trueOnly active records
current.isNewRecord()Only on insert
current.priority.changes()Only when priority changes
gs.hasRole('admin')Only for admins
current.assignment_group.nil()Only when unassigned

Performance Best Practices

  1. Use conditions - Limit when the rule runs
  2. Keep Before rules fast - No queries if possible
  3. Use Async for integrations - Don't block transactions
  4. Avoid Display rules - Slows form load
  5. Set Order - Lower numbers run first (100-500 range)
  6. Check "when to run" - insert, update, delete, query

Common Patterns

Auto-Assignment

javascript
// Before Insert/Update
if (current.assignment_group.changes() && !current.assignment_group.nil()) {
  var members = new GroupMembers(current.assignment_group)
  current.assigned_to = members.getNextAvailable()
}

Cascade Updates

javascript
// After Update
if (current.state.changesTo(7)) {
  // Closed
  var tasks = new GlideRecord("task")
  tasks.addQuery("parent", current.sys_id)
  tasks.addQuery("state", "!=", 7)
  tasks.query()
  while (tasks.next()) {
    tasks.setValue("state", 7)
    tasks.update()
  }
}

Frequently asked questions

What does the Business Rule Patterns AI skill do?

Write ServiceNow business rules (before/after/async/display) — current vs previous, changesTo/changesFrom, recursion avoidance, setAbortAction, and async dispatch for heavy work.

Why use Business Rule Patterns on TypingMind?

Because you install it once and use it with any model. Business Rule Patterns is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Business Rule Patterns in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/serac-labs/serac/tree/main/packages/skills/business-rule-patterns. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Business Rule Patterns?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Business Rule Patterns?

As many as you like. As long as a model supports skills, you can use Business Rule Patterns with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Business Rule Patterns AI skill free?

Yes. It is published on GitHub by serac-labs under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇