Comments after return in Client Method leads to 'event handler' error

Hi community,

I discovered a strange behavior in Innovator 12. 

Let´s assume we have a regular Form with a button that uses the following onClick event:

alert("This is just a test button event");
return;
// Todo for later: add additional validation

This Method will lead to the following error Message:

'Event handler' failed with the message: ReferenceError: func $ BD472BC271CA48E88DE6CB0C7E3CED75 $ _onclick2 is not defined

I noticed that the Method works fine, as soon as I remove the comment behind the return. Of course in normal code we most of the time do not have any additional comments after the final return.
But when creating new Methods, I often place later used code at the bottom so I can take care for it later.
Comments after the return statement were never any problem in Innovator 11. It took me quite a few days until I finally discovered why certain parts of my new code never worked.
Is there an explanation for this new behavior? Are there any other new design rules to consider when programming in Innovator 12?

Would be happy about any hints to avoid similar effects!
Thanks!
Angela


  • Oh my god Angela, THANK YOU!
    I've been getting that error randomly (or so I thought) for a while now in Innovator 12, and I never knew what caused it.
    I tested it myself as well and could reproduce it, just like you said. That might just be the weirdest Aras error I have come across yet.
    I have no idea right now how to fix/work around it, but I needed to reply just to say thank you .

  • Hi Angela,

    Thanks for pointing this out. I was able to reproduce this in my local instance of 12.0 SP1 and SP3. It seems this is caused in the code that's responsible for building the actual HTML events in the form. When the event is built, the method code is inserted into an anonymous function with code similar to the line below:

    "function() {" + the_method_code + "}";

    When the final line of the method is a comment, it seems it's also commenting out that closing bracket of the anonymous function which is causing the error you're seeing. 

    I've filed a ticket for this issue. In the meantime, you can workaround this by either not using comments on the last line of your Field Events or by adding an extra newline to the end of your function. However, I wouldn't count this as a "design rule" exactly since this workaround only seems to be necessary for Field Events specifically. I also tested the same method code in an onLoad Form Event as well as a Client Action and both of those worked as expected.


    Chris

    Christopher Gillis

    Aras Labs Software Engineering