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 Smiley.

  • 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

  • @ Cogres: You´re welcome! I am happy that I am not the only person that has to face Innovator's small challenges.Upside down Innovator 12 is sometimes a little bit of a diva. I felt like Sherlock Holmes until I discovered what´s going on. One of his quotes fits very well: "When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth."

    Thanks Chris for confirming that issue is not caused by some kind of design rule update. It´s easy to avoid and somehow even funny...once you know how to avoid it.

  • Hi Chris,

    do you know if this error has already been resolved in some of the latest Innovator versions? I got the same error message when trying to use async functions in a client Method. E.g.:


    async function mytest() {

      var promise = new Promise((resolve, reject) => {
      setTimeout(() => resolve("done!"), 1000)
    });

    var result = await promise;

    alert(result);
    }

    mytest();

    This one will lead to the error message when I run the Method with a Form onClick button event:

    Event handler' failed with the message: "func $ B939B3B5930742458E4CB9100BF6E284 $ _onclick2" is undefined


    But the error only will appear in Internet Explorer 11. Not in Chrome or Firefox. After some reading a figured out async/await is supported for all browsers, expect IE11. But I thought it worked in the past. 
    So I am not sure if this one is related to the browser, or just related to this simple little Innovator glitch.

    I really pray it´s not the browser GrinI wanted to use async/await cause it´s much more simpler to use than chained promises. In my current use case I have so many that it´s hard to keep an overview.

  • Hi Angela,

    Based on the description, this sounds like a browser issue unfortunately. You're probably seeing a similar error message because the async/await keywords are not recognized and thus lead to invalid syntax. I also prefer to use async/await since I think it's easier to understand, and I can confirm that it is possible to use with Innovator in general.

    Chris

  • Hi Chris,

    well, the "wrong syntax" indicators are also displayed in Chrome, but the code still worked. So I ignored this warning and was happy that I found an easy solution for my 9 chained promises with error handling and everything else.

    This table about the async support of browsers right now makes me cry:

    Even if most people today don´t use IE anymore, you will always have a few left.

    The easiest solution would be, if Aras just discontinues IE11 support for Innovator. This would give me the easiest excuse not to rewrite the code to regular promises. :)
    But I assume Aras faces the same challenge. There are always a few customers that still use IE. We will probably still see it the next 10 years.

  • Hi Angela,

    You're in luck about that easiest solution. :)

    In 12.0 SP6, support for IE11 has officially been dropped. I can confirm that in my 12.0 SP6 test instance I get redirected to the unsupported browser page when trying to connect through Internet Explorer.

    For older service packs, we are still supporting IE through the end-of-life of those service packs themselves.

    Chris

  • Praise the lord! I've never been so happy about a discontinued feature like I am now.Grinning