What is the Difference between Display BR and onLoad client script other than one is server side script and another is client side
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2021 11:30 AM
Difference between Display BR and onLoad client script with demo in personal instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2021 11:39 AM
The primary difference is that a display business rule can save something to the scratchpad that isn't available in a client script running on that record.
One example is to get the value of a record field that isn't displayed on the form.
Save it to the scratchpad:
g_scratchpad.u_priority_status = current.u_priority_status;
Read it in a client script:
if (g_scratchpad.u_priority_status == "urgent") {
// do something here
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2021 11:47 AM
Hello,
It's unfortunate that you chose to delete your post after I provided a response as well as reference several pieces of documentation...only to post your question again.
But...I'll copy and paste this as needed:
Please take a moment and search the documentation yourself and then let us know what questions you may have:
Display BR: https://docs.servicenow.com/bundle/paris-application-development/page/script/business-rules/concept/...
Client Script: https://docs.servicenow.com/bundle/quebec-application-development/page/script/client-scripts/concept...
Display BR allows you to set scratchpad that you can use to bring server information directly in to the record onLoad.
onLoad client script is client side scripting and it's still needed to utilize the scratchpad brought from the display BR anyway.
So they're still connected in that way.
Please mark reply as Helpful/Correct, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
display business rule run when an form record is open before save the data to the data base and onload is same but run on client side when an user open a from record after open to the form record it run.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Beyond server-side vs client-side, the main differences are timing and what each script can access. In practice the two are used together.
1. When they run
- Display Business Rule: runs on the server after the record is read from the database and before the form is sent to the browser. It runs only when a form is displayed. It does not run for lists, imports or web services.
- onLoad Client Script: runs in the browser after the form has rendered.
2. What they can access
- Display BR: has the full server-side API (GlideRecord, gs, current). It can query other tables and read fields that are not on the form. It cannot touch the UI (no g_form, no hiding or showing fields).
- onLoad Client Script: has g_form and g_user, so it can set values, make fields mandatory or read-only, hide sections and show messages. It only knows what is on the form. To get more from the server it needs GlideAjax, which is an extra server round trip.
3. How they work together (g_scratchpad)
The Display BR puts server-side data into g_scratchpad, including values from fields that are not on the form. The onLoad Client Script then reads g_scratchpad and acts on it in the UI.
Example:
// Display Business Rule (server)
g_scratchpad.isVIP = current.caller_id.vip.toString();
// onLoad Client Script (browser)
function onLoad() {
if (g_scratchpad.isVIP == 'true') {
g_form.showFieldMsg('caller_id', 'VIP caller', 'info');
}
}
4. Why it matters
Using a Display BR with g_scratchpad sends the server data along with the form. You don't need GlideAjax, or slow synchronous calls like getReference() or a client-side GlideRecord, after the form loads. That makes it the best-practice way to get server data you need when the form opens.
Rule of thumb: Display BR = prepare server data. onLoad Client Script = change the UI. Most real cases use both.