ORACLE APEX Dynamic action - apex.item and this.triggeringElement
A perfect JavaScript expression usecase
If you ever wanted to trigger your DA based on an item that is a select list here is a quick read.
Scenario here is we want to trigger an action when item we interacted with contains a certain string like NBME in my case. How would we do this?
To be 100% correct we want to check it against the item display value and not its return value (one hidden from the end users).
I strongly encourage you to visit apex.oracle.com/jsapi for a full reference of apis available to us.
We all know about apex.item api which can easily give us the value of the item with something like apex.item("PX_TEST_CODE").getValue()
Problem here is that if we were to do this we would have gotten a value of return value from my select list item and not the one we are using as display.
Fair enough we have also a function called displayValueFor() which sounds like our thing.
If we pack it all together on our DA Client side condition we can do JavaScript expression with following code:
apex.item(this.triggeringElement)
.displayValueFor(apex.item(this.triggeringElement).getValue())
.includes('NBME')
What this will do is take our a return value of triggering element then it will get a display value of it in an item that is triggering it. At the end it will check it if it includes NBME string and return true or false as a result of it all.
It seemed I was coming back to it a few times so wanted to write it down somewhere.
Happy APEXing,
SLino