- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 10:00 PM
Can someone explain the purpose of below predefined function in business rules.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Change Management
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 10:11 PM
It's one of the template of writing your code within BR
The Script field is pre-populated with that template.
The function syntax is known in JavaScript as a self-invoking function or an Immediately Invoked Function Expression (IIFE). The function is immediately invoked after it is defined. ServiceNow manages the function and when it is invoked; developers do not explicitly call Business Rule Scripts.
Sharing the common syntax
1) Method 1
(function executeRule(current, previous /*null when async*/) {
// Add your code here
})(current, previous);
2) Method 2 - Define your function and use your code
restrictIncidents();
function restrictIncidents() {
// your code here
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 10:21 PM
Hi,
those are the parameters to the self-invoked function
the current and previous objects will help to fetch the previous and current value from the record on which BR runs
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2022 04:27 AM
I found a question on a practice paper for the CAD exam.
Here is the Business Rule script template:
(function executeRule (current, previous */null when async*/){})(current,previous);
This type of JavaScript function is known as:
1. Constructor
2. Scoped
3. Anonymous
4. Self Invoking
I gave 4 as the answer but was advised that this was incorrect and that the answer is 2. Can anyone confirm either way please? @Ankur Bawiskar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2022 05:05 AM
From my understanding it's option 4.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2022 05:09 AM
I'd imagine that, if that's what you think then it must be true.
Thank you again Ankur.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 10:28 PM
Can anyone please help me to understand the issue, how can I resolve it .am I missing any plugins?