Skip to tutorial content
Rate module Not yet rated

Async & Display Rules

3 min read
On this page

In this lesson, you will learn:

  • What async business rules are, and why they help
  • What display business rules do
  • How g_scratchpad passes server data to client scripts

1 Async: don’t make the user wait

Some work is slow, like calling another system or doing heavy math. If an after rule does that, the user stares at a spinning icon. An async rule does the work in the background, so the user can move on. πŸƒ

Key term: Async business rule

A rule that runs after the save, but in the background, a moment later. The user doesn’t wait for it.

  • Good for: sending data to other systems, heavy updates, calculations that aren’t needed right away.
  • previous is not available in async rules. By the time it runs, the old values are gone.
  • You’ll find queued async work as scheduled jobs in System Scheduler.

2 Display: prepare data for the form

Client scripts run in the browser. Sometimes they need data that only the server knows, like “Is the caller a VIP?” A display rule gets that data while the form is loading.

Key term: Display business rule

A rule that runs when a record is loaded to show on a form. It puts data into g_scratchpad for client scripts to use.

Two special business rules. Display: when the form loads, the display rule runs on the server and sets g_scratchpad.isVip to true. The form arrives in the browser, and an onLoad client script reads g_scratchpad.isVip and shows a VIP caller message. Async: the user saves the record and sees the form right away. A moment later, in the background, the async rule sends the incident to another system.
Figure 1. Display rules feed client scripts. Async rules work in the background.

Display rule (server):

(function executeRule(current, previous) {
  g_scratchpad.isVip = current.caller_id.vip == true;
})(current, previous);

onLoad client script (browser):

function onLoad() {
  if (g_scratchpad.isVip) {
    g_form.addInfoMessage('⭐ VIP caller. Please give extra care.');
  }
}

πŸ’‘ Good to know: g_scratchpad is much faster than calling the server from a client script. The data rides along with the form, with no extra trip.

⭐ Remember: Async = background, no previous. Display = runs on form load, fills g_scratchpad.

3 All four “When” values

When Runs Typical use
before Before the database write Change or check this record
after Right after the write Update related records
async After the write, in the background Slow work, integrations
display When a form loads the record Fill g_scratchpad for client scripts

4 Let’s try it: VIP message

  1. Make a user a VIP: open Riya Sharma‘s user record and check VIP (add the field to the form if needed).
  2. Create a business rule on Incident: When display. Check Advanced. Paste the display script.
  3. Create an onLoad client script on Incident. Paste the client script.
  4. Open an incident where Riya is the caller. Do you see the VIP message?

5 Quick recap

  • Async rules run in the background after the save
  • previous isn’t available in async rules
  • Display rules run when a form loads
  • Display rules pass data to client scripts with g_scratchpad

6 Check yourself

Think of your answer first. Then tap to check.

1 You need to send data to an outside system after a save, without slowing the user. Which When? Show answer

async.

2 What object does a display rule use to send data to client scripts? Show answer

g_scratchpad.

3 Can an async rule use previous? Show answer

No. previous is null in async rules.

Nice work! You finished this lesson. πŸŽ‰

Was this lesson helpful?

Have a question or doubt?

Ask here and get help from instructors and fellow learners.

0 / 300

Only logged-in learners can post.