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:


async () => {
    console.log("Test");  
}

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?

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 theUserFunction.Test when I press a button. Do you have a solution for this?

In Appstudio version 1.1.0, I get an error message when I press the button. the following popup will appear:

Event Trigger Error
'UserFunction' not defined

I have the same problem — is there already a solution for this so that the functions can be used?

Hi Jur,

I could not find the problem, so I made a new project and started all over again. For some reason it works fine in the new project now. I hope this works for you too.

Hi Yvok,

I have now also created a new project and it does indeed work now. Is there a way to convert the old project to a new project so that the userfunctions now work?

Hi Yvok, Hi Jur,

I’m experimenting the same problem with a project, created with AppStudio 1.0.0 and now edited with 1.1.0. I’ve also created a new project on 1.1.0, same problem.

Have you found the reason behind this error?

I tried with a very very simple Add function (the same shown in documentation userfunction).
It turns out that:

  • Using Chrome to open the App, no problem. calling UserFunction.Add(1,3) → gives you 4.

  • On the ABB FlexPendant, prints “Event trigger error”. Looks like userfunction is not defined.

Calling console.log(‘UserFunction.Add is defined:’, typeof UserFunction.Add === ‘function’);
On Chrome print TRUE, on flexpendant doesn’t print anything.

It seems the pendant runtime isn’t injecting my project.js top-level function declarations into the UserFunction namespace.

Have you encountered this, or do you know what might be causing it? Any pointers would be much appreciated.

Thanks,

Filippo

I’ve even tried invoking the UserFunction after the entire app has loaded —using a button’s onClick handler— but it still fails.

Have you tried setting the flexpendant to use the Chromium browser?