We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

bussiness rules

PavanBalajT
Giga Contributor

use of scratchpad in bussiness rules

4 REPLIES 4

PA001
Mega Sage

Hello Pavan,

 

Please refer below article

https://www.servicenow.com/community/developer-articles/display-business-rule-and-g-scratchpad/ta-p/...

 

Mark the article as helpful and bookmark if you found it useful.

Dinesh Chilaka
Tera Guru

Hi @PavanBalajT ,

To access the g_scratchpad variables from display business rule .

Business Rules run server-side. On form load, Display Business Rules execute first, followed by client-side Client Scripts.

To display form content (messages, field values, UI changes) after the Display Business Rule finishes, use g_scratchpad to pass data from server to client scripts.

In Display Business Rules, set variables like g_scratchpad.variableName = value. Client Scripts can then access them using g_scratchpad.variableName.
If my response helped, mark it as helpful and accept the solution.

Ankur Bawiskar
Tera Patron

@PavanBalajT 

your question is easy.

Answer to this can be easily found on google or any AI tool

where are you stuck in case you are working on something?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

yashkamde
Kilo Sage

Hello @PavanBalajT ,

 

g_scratchpad is an object used to pass information from a Display Business Rule to a Client Script. Since Client Scripts are "expensive" (they make the browser wait if they have to call the server via GlideAjax), the scratchpad allows you to grab the data you need while the server is already processing the record and "hand it over" to the browser in one go.

 

For Ex : You want to show an alert or hide a field if the user's Manager is "System Administrator," but the "Manager" field isn't on the current form.

 

BR script : (Display)

(function executeRule(current, previous) {
    var userObj = gs.getUser().getManagerName(); 

    g_scratchpad.managerName = userObj;
})(current, previous);

 

OnLoad client script :

function onLoad() {
    // No need for GlideAjax or getReference!
    if (g_scratchpad.managerName == 'System Administrator') {
        g_form.addInfoMessage('Note: Your manager is the System Admin.');
    }
}

 

Note : Only use g_scratchpad for Display Business Rules. While it technically exists in other types, its primary purpose is this server-to-client handoff.

 

If my response helped mark as helpful and accept the solution.