TestProject Forum

Why is element parameter not used for Element actions?

I’m new to TP Add-on development and I am confused as to why there is an “element” parameter for the execute method of the various XxxElementAction interfaces, but we’re told not to use it! Instead, we’re instructed to copy-paste the same bit of code, helper.getSearchCriteria() (plus error handling) into each and every action body, but it’s not explained why (that I’ve found, either here or in the one page of docs).

If it’s the same code every time, why not do the call in the framework and pass the value — as one would expect, looking at the interface? Maybe there’s a good reason, but to me, this goes against the principle of least surprise, so this is a case where it would be really helpful if the documentation provided some explanation.

Hi @dusty.rhodes.
The element parameter is an old mechanism that was previously part of the SDK. In the most recent addons SDK it will always be null, and the element is searched inside the action itself using the helper.getSearchCriteria(). Please be aware that this value is only set for actions that implement any of the ...ElementAction interfaces.

@shai.glatshtein_prd: Yes, I got that from the ReadMe in the Addons Examples repo. But it doesn’t explain why it isn’t used, when the value seems to always be obtained the same way, using something that the framework has. And the framework could handle the “no match” case as well. It’s 2-4 extra lines of code that has to be repeated where it seems like the value could simply be supplied.

Without any other examples, it is really hard to see why this was done. I guess I’m a “curious bird”, and I like to understand the reasoning behind such things … especially when I have to explain it to someone else and it makes no sense to me!