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();