How can I call a userfunction onClick with a button?

I use a button in my webapp, and I want to call a function when the button is clicked. It did not work, so I tried it again with some simple code.
The simple code that I tested on is:

<div>async () => {</div><div>&nbsp; &nbsp; console.log("Test");&nbsp; <br>}</div>


And the code on the onClick of the button is:

await UserFunction.Test()

When I click on the button, the userfunction won't run. How can I fix this?

Answers

  • Hi, 

    I saw that you're trying to use `console.log` in your `UserFunction.Test`. This method prints content to the browser's console, which is suitable for viewing debug information when opening a deployed application in a browser.

    If you want to display debug information on Flexpandent, you should use `Logger.i()`, which supports printing messages like strings, numbers, and more, 
    And make sure to check 'Show debug log on the tech pendant UI' when deploying the webpage.

    Thanks.


  • Thank you for the reply. I will use this logger in my code from now on.

    It still does not fix the problem with calling the`UserFunction.Test` when I press a button. Do you have a solution for this?
  • YvoK
    YvoK
    In Appstudio version 1.1.0, I get an error message when I press the button. the following popup will appear:

    Event Trigger Error<br>'UserFunction' not defined<br>