Thursday, August 27, 2015

CRM WebUI Get related entities and Parent entities



If you need to get entities related (child entities), use GET_RELATED_ENTITY, GET_RELATED_ENTITIES methods

Using GET_RELATED_ENTITY:

    lr_erpadminh ?=   me->typed_context->erpadminh->collection_wrapper->get_current).
    CHECK  lr_erpadminh IS BOUND.
    lr_erpadminh->get_property_as_value(  EXPORTING   iv_attr_name =   'VBELN'
                                          IMPORTING   ev_result    =   lv_vbeln .

*    CHECK  lv_vbeln IS NOT INITIAL.
    TRY.
        CALL METHOD lr_erpadminh->get_related_entity
          EXPORTING
            iv_relation_name 'ERPHeaderCondSet'
*           iv_mode          = normal
          RECEIVING
            rv_result        lr_erpcondh.
      CATCH cx_crm_genil_model_error .
    ENDTRY.
    IF lr_erpcondh IS BOUND.
      TRY.
          CALL METHOD lr_erpcondh->get_related_entities
            EXPORTING
              iv_relation_name 'ERPCondHAll'
*             iv_child_name    =
*             iv_mode          = NORMAL
*             iv_owned_only    = ABAP_FALSE
            RECEIVING
              rv_result        lr_condcol.
        CATCH cx_crm_genil_model_error .
      ENDTRY.


      CLEAR  lr_iterator ls_condtype.
      lr_iterator   lr_condcol->get_iterator).

Full code link: http://sapist.blogspot.co.uk/2015/08/crm-web-ui-getrelatedentity.html


If you need parent entities, then use GET_PARENT method

Using GET_PARENT method:

    if iterator is bound.
      current iterator->get_current).
    else.
      current collection_wrapper->get_current).
    endif.

    lr_current ?= current.

    TRY.
      lr_bt_statush ?= lr_current->get_parent).

      CATCH cx_crm_genil_model_error .
    ENDTRY.

    TRY.
      lr_bt_adminh ?= lr_bt_statush->get_parent).

      CATCH cx_crm_genil_model_error .
    ENDTRY.

    TRY.

    lr_bt_adminh->get_property_as_value(  EXPORTING IV_ATTR_NAME 'PROCESS_TYPE'
                                            IMPORTING EV_RESULT lv_process  ).

      CATCH cx_root.
    ENDTRY.

Full code link: http://sapist.blogspot.co.uk/2015/08/crm-web-ui-getparent-method.html

No comments:

Post a Comment