cancel
Showing results for 
Search instead for 
Did you mean: 

Need to default the Sales Org for Account in BP_HEAD Save

Former Member
0 Kudos

Hi,

When we create an Account/Company, we need to default the Sales Org on SAVE.

So we have written the following code in EH_ONSAVE of the BP_HEAD/BPHEADOverview of BP_HEAD component where we are trying to created the related entity - 'BuilSalesArrangementRel' and then setting it:

lr_core = cl_crm_bol_core=>get_instance( ).

  lr_comp_controller ?= me->comp_controller.

  IF lr_comp_controller IS BOUND.

    lr_entity ?= lr_comp_controller->typed_context->partner->collection_wrapper->get_current( ).

  ENDIF.

TRY.

        lr_salesorg ?= lr_entity->get_related_entity( iv_relation_name = 'BuilSalesArrangementRel' ).

      CATCH cx_crm_genil_model_error.                   "#EC NO_HANDLER

      CATCH cx_sy_ref_is_initial.                       "#EC NO_HANDLER

ENDTRY.

lv_region = '220'.

    TRY.

        IF lr_salesorg IS NOT BOUND.

          lr_entity->create_related_entity( iv_relation_name = 'BuilSalesArrangementRel' ).

          lr_salesorg ?= lr_entity->get_related_entity( iv_relation_name = 'BuilSalesArrangementRel' ).

        ENDIF.

       

            IF lr_salesorg->is_changeable( ) NE abap_true.

              lr_salesorg->switch_to_change_mode( ).

            ENDIF.

            ls_sales_area-sales_org = 'O 50000057'

            ls_sales_area-channel = '01'.

            ls_sales_area-division = '01'.

            CALL FUNCTION 'CRM_BUPA_GET_SALES_AREA_PROPS'

              EXPORTING

                is_sales_area_keys = ls_sales_area

              IMPORTING

                es_sales_area      = ls_assigned_sales_areas_new.

            MOVE-CORRESPONDING ls_assigned_sales_areas_new TO ls_sales_area_il  .

            lr_salesorg->set_properties( EXPORTING is_attributes = ls_sales_area_il  ).

      CATCH cx_crm_genil_model_error.                   "#EC NO_HANDLER

      CATCH cx_sy_ref_is_initial.                       "#EC NO_HANDLER

    ENDTRY.

    lr_core->modify( ).

CALL METHOD super->eh_onsave

    EXPORTING

      htmlb_event    = htmlb_event

      htmlb_event_ex = htmlb_event_ex

    IMPORTING

      ev_success     = ev_success.

In the debug mode, I can see that lr_entity has the related entity - ' BuilSalesArrangementRel'  and it has the sales org data in it.

However, Once the SAVE happens and Company is created, when I go to GENIL_BOL_BROWSER and try to view the entities, I see that ' BuilSalesArrangementRel'  has no entries in it whatsoever.

Is there something I am missing.

I also tried with the snippet :

    lv_transaction = lr_core->get_transaction( ).

    lv_transaction->save( ).

   lv_transaction->commit( ).

However, this did not work either. Kindly help.

Regards,

Nisha

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member541649
Active Participant
0 Kudos

Hi,

Have you tried simulating this in genil_bol_browser? There might be some configuration/BAdI overwriting your code. I would suggest you do the exact things you are doing in your code in the BOL browser.

Also, it is not recommended to call FMs like this from the UI, you should consider moving your code to the appropriate BAdI.

Regards,

Parul