you can take reference from from below code as in above case we use BuilHeaderAdvancedSearch search object, to get current entity.
data: query TYPE REF TO cl_crm_bol_dquery_service,.
query ?= me->typed_context->BuilHeaderAdvancedSearch->collection_wrapper->get_current( ).
Do not remove code from getter setter of fields , it will not clear.
Check with http://scn.sap.com/thread/3391203 , for basic understanding of UI.
Regards,
Harish Kumar