cancel
Showing results for 
Search instead for 
Did you mean: 

Access BOL - dependent object

stefan_porges1
Participant
0 Kudos

Hi,

I try to access a dependent object of a BOL.

For that I used the BTQuery1O.

qs = cl_crm_bol_query_service=>get_instance( 'BTQuery1O' ).

Now I tried this:

result ?= qs->get_query_result( ).

lv_or_ent ?= result->get_first( ).

lv_bp_ent_adr2 = lv_or_ent->get_related_entity( 'BTRefObj' ).

-> But this results in a CX_CRM_UNSUPPORTED_RELATION Exception. Can anyone tell me how to access this dependent object?

Thanks in advance Paul

Accepted Solutions (1)

Accepted Solutions (1)

suchita_phulkar
Active Contributor

Hi Paul,

Please note that there is no Relation called 'BTRefObj' and hence you have the said exception.It is not relation but the related BOL entity.

Also, I see that you are not setting any search criteria. Due to this, the Query will return all the OneOrder documents - By default , first 100. It is Ok that you are just reading the first, but just wanted to let you know that ideally you should set the search criteria to get the correct oneorder object that you want.

If you have Object ID ( for ex. a sales order number ), and want to find the related 'BTRefObj' entiy of this object id , then you shouls set it as the search criteria.


* Create a query service
      lr_query = cl_crm_bol_query_service=>get_instance( 'BTQuery1O' ).

* Set a search criterion
      lr_query->set_property( iv_attr_name = 'OBJECT_ID' iv_value = lv_object_id ).

* Execute query and receive result
      lr_result = lr_query->get_query_result( ).

* Use iterator to access entities in query result
      lr_iterator = lr_result->get_iterator( ).

      lr_root = lr_iterator->get_first( ). " entity is always BTOrder

" Retrieve BTAdminH 
      lr_entity = lr_root->get_related_entity( iv_relation_name = 'BTOrderHeader' ).
      CHECK lr_entity IS BOUND.
     
   lr_entity = lr_enity->get_related_entity( iv_relation_name = 'BTHeaderBOSSet' ). " entity is BTBOSSet
  CHECK lr_entity IS BOUND.

 " now you have to dig further through required relations to get the correct reference object entity of BTRefObj.

Use transaction GENIL_MODEL_BROWSER with component set ONEORDER.

Check root BTOrder and then relations to BTAdminH and then further digdown in BTAdminH relations as coded above, when you arrive at 'BTHeaderBOSSet you will see that it has several other relation. You need to find out what relation will give you your required entity.

For that use transaction GENIL_BOL_BROWSER with compoent set ONEORDER.

Take the BTQuery1O query and execute with an object ID. Now use Get Children button on right panel and dig through the relations on Left panel. You always get result objects in bottom left panel. Dig through to check whihc relation of 'BTHeaderBOSSet is giving you what you want and then implement the same in the code sample given above.

Hope this helps.

Thanks & Regards

Suchita

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

As Mr.Harshit said you can see the list of suported relations in runtime and make use of the is relavent one.

The relation 'BTRefObj' is not directly related but it is aggregated by Dependent Object BTRefObjSet and this is agregated by Dependent Object BTBOSSet.

If the object 'BTBOSSet' is there in the list of suported relations at runtiem you can read this relation first and from this you can read the other child relation as required. Hope this is help full.

Thanks,

Rajini Aleti.

former_member189678
Active Contributor
0 Kudos

Paul,

You can check at runtime what all related entities are supported by making use of method get_related_entities. Once you know, modify your code and logic accordingly.

Regards,

Harshit Kumar