Skip to Content
author's profile photo Former Member
Former Member

Need to default the Sales Org for Account in BP_HEAD Save

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Oct 22, 2015 at 08:55 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.