- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2015 01:51 AM
Hi SNC,
I am trying to write a Business Rule but whatever I do I get this message: Missing function declaration for onBefore.
I am on Fuji, and have never seen this so far.
Would appreciate any tips on what I am doing wrong.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2015 01:56 AM
Hi..
In fuji, write the code inside that function
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
// your code here
}
or
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed
}
// your code here
Thanks'
Harish
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2015 06:01 AM
Phew
Thanks for the answer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2016 09:45 AM
I have a similar issue. But getting the error: Missing function declaration for onAfter.
Would I add the following to the script?
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed
}
// your code here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2016 07:22 PM
Yup, you just need to have the corresponding function depending on the "When" value of the business rule.
Not every function has access to both "current" and "previous," though (e.g., "function onAsync(current)"). You could figure this out using the Wiki (or you could just start a brand new business rule and see what the system populates for you).
On a related note, I just realized that there's now an "Execute Function" field on business rules deciding whether or not these functions will be automatically run. (If you also get the crazy idea to try manually converting a pre-Fuji business rule to the new approach, make sure you set this field to true!)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2016 10:07 PM
Hey please give us code for examples
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 06:19 AM
Well, this is interesting. We just upgraded one of our instances from Fuji Patch 12 Hotfix 1 to Helsinki Patch 1, and the implementation is slightly different.
In Fuji P12H1, the default Script you're provided with depends on the When selection you make. For example, "before" business rules start with:
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
}In Helsinki P1, the default Script you're provided with is always the same:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
})(current, previous);
In any version, be mindful of what global variables are actually available to you.
Fuji and earlier: Scripting in Business Rules - ServiceNow Wiki
Helsinki (and I assume Geneva, as well): Using predefined global variables
P.S., continuing my "related note" from my last post, it looks like my personal revelation isn't really relevant anymore, hah. By moving the default script to a self-executing function, business rule scripts are able to run without dependencies on any other fields while still being safely enclosed in functions. Well done, ServiceNow developers!