Forum Discussion

Morgan's avatar
Morgan
Ideator I
3 years ago
Solved

Adding a CUI button, getting context item

Hi aras team,

I am adding a cui button to the command bar, but random question...

How can I get the context item for my method? The usual ways don't seem to apply and I am getting an error:

"identifier 'options' has already been declared"

the onClick event I setup has attempted to run against document.item, document.thisItem and I also tried parent :/

All the blogs seem to focus on get selected items in a grid, not the active window item.

  • "options" is declared as the parameter of your onClick method and has the "itemId" and "itemTypeName" properties. Or you can use window.item.

7 Replies

  • "options" is declared as the parameter of your onClick method and has the "itemId" and "itemTypeName" properties. Or you can use window.item.

    • Morgan's avatar
      Morgan
      Ideator I

      Thanks for this info, is there any documentation on CUI out there? The admin guide is pretty abysmal. I feel like I may run into more situations like this.

      • alaxala's avatar
        alaxala
        Ideator I

        I have long come to terms with the fact that there is no good documentation and never will be. The only support for the community is the debugger and sources.

        I didn't know anything about "options" three days ago. All I did was add a CUI button, an "Item Click" method with one line:

        debugger;

        turned on developer tools in the browser and pressed the my button.

        And voila, now I see the whole context of my "Item Click" method with its parameters, their properties, properties and methods of the "window", "document" etc. And now I know about "options".

        Unfortunately this is the only way to do something beyond the documentation examples.

  • This discussion reminds me to this post where I tried to figure out to call a Method from everywhere: https://community.aras.com/f/development/3996/call-same-client-method-from-different-locations-action-cui-form-button

    The post shows a combined CUI call mentioned that works for Grid and Form. But it´s maybe not the best variant anymore. Using "options" as outlined by Alaxala is probably the more modern approach.

    "options" is a hidden variable used by the CUI element. As Alaxala says, it contains the itemId - or even multiple ones when we came from a grid and user selected 10 items at once. So it´s most of the time the most flexible variant if you reuse the Method at many locations.

    If you just use the CUI element in a Form, you can get the full context similiar to document.thisItem like this:

    const myItem = thisItem;

    const myId = thisItem.getId();