Missing function declaration for onBefore error on Business Rule

mitzaka
Mega Guru

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.

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

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


Regards
Harish

View solution in original post

19 REPLIES 19

Hi Michael,



So do I check the Execute Function box or not?   What does "automatically run" mean in this case?   Wouldn't the business rule run if the condition is met?   I just wrote a new business rule in Helsinki patch 6, and I cannot get it to execute.   I tried both checking the Execute Function box and un-checking.   The debugger shows this:



Capture.JPG


Here's my business rule (attached as pdf).   The gs.addInfoMessage never displays, so it's not even going into the function.



Any help is greatly appreciated!



Thanks,



Laurie


Hi Laurie,



I think your script is currently living in both worlds by having both "executeRule" and "onBefore" functions defined.



I believe checking the Execute Function box tells the system to look for a function called "onBefore" and automatically run that. With that box checked, you can just start your script the old way with...


function onBefore(current, previous) {



If your script starts the new way with...


(function executeRule(current, previous /*null when async*/) {


...then the Execute Function box is not necessary because you have a self-executing function: once all conditions are met, the system will automatically run the code inside of that opening parenthesis.



Your options should be:


1) Check the Execute Function box, then remove all of the "executeRule" stuff and start with "function onBefore" in your Script.


2) Un-check the Execute Function box, then start your code immediately within the "executeRule" function (meaning your second line would be "gs.addInfoMessage..." in this case).



The second option is the new standard, so you may want to try un-checking the box, then deleting the "function onBefore" line (as well as its closing curly brace below). Good luck!


Michael, you are a gem!   You explanation makes perfect sense!   I was unable to find that information on the wiki.   I'm not a master coder, but I can code simple stuff.   How did you know about this change?



Thanks,



Laurie


Hah, you're too kind. I wish I had a better answer for you, but I came to my current understanding about this business rule situation as I often do: with a little Wiki/Documentation browsing, after some Community assistance, and following plenty of good old fashioned trial-and-error!


At lease I'm on the right track!   That's pretty much what I do, too!