cancel
Showing results for 
Search instead for 
Did you mean: 

Account (BP) email address not being updated

former_member192561
Participant
0 Kudos

Hi,

I need to update/change the existing standard email address maintained in the communication  tab of BP . The following does not seem to update the email and I seem to be lost . Any suggestions are very much appreciated ?

METHOD update_email_adress.


   DATA: lr_core        TYPE REF TO cl_crm_bol_core.
   DATA: lr_result      TYPE REF TO if_bol_entity_col,
         lr_qs          TYPE REF TO  cl_crm_bol_query_service,
         lr_iterator    TYPE REF TO if_bol_entity_col_iterator,
         lr_etr         TYPE REF TO if_bol_entity_col_iterator,
         lr_entity      TYPE REF TO cl_crm_bol_entity,
         lr_adrscol     TYPE REF TO if_bol_entity_col,
         lr_adrs        TYPE REF TO cl_crm_bol_entity,
         lr_emailcol    TYPE REF TO if_bol_entity_col,
         lr_email       TYPE REF TO cl_crm_bol_entity,
         ls_bapiemail   TYPE bapiadsmtp,
         lr_transaction TYPE REF TO if_bol_transaction_context,
         lv_std         TYPE string.

   READ TABLE it_bapiemail INTO ls_bapiemail INDEX 1.
   CHECK sy-subrc = 0.
   TRY.
       lr_core = cl_crm_bol_core=>get_instance( ).
       lr_core->start_up( 'ONEORDER' ).
*& Get and prepare dynamic query service.
   lr_qs ?= cl_crm_bol_query_service=>get_instance( 'BuilHeaderSearch' ).
       lr_qs->set_property( iv_attr_name = 'PARTNER'    " Component Name
                                iv_value = iv_businesspartner ).
*& Execute query search result
       lr_result = lr_qs->get_query_result( ).
       CHECK lr_result IS BOUND.
*Use Iterator to access entities in query result
       lr_iterator = lr_result->get_iterator( ).
       CHECK lr_iterator IS BOUND.
       lr_entity = lr_iterator->get_first( ).
*      lr_entity = lr_result->get_first( ).
       WHILE lr_entity IS BOUND.
         lr_adrscol = lr_entity->get_related_entities(
             iv_relation_name = 'BuilAddressRel' ).
         lr_adrs = lr_adrscol->get_current( ).
         CHECK lr_adrs IS BOUND.
         lr_emailcol = lr_adrs->get_related_entities(
             iv_relation_name 'BuilAddressEMailRel' ).
         lr_etr = lr_emailcol->get_iterator( ).
         lr_email ?= lr_etr->find_by_property( iv_attr_name 'STD_NO'
                                                   iv_value 'X' ).
         CHECK lr_email IS BOUND.
         IF   lr_email->lock( ) = abap_true.
           lr_email->switch_to_change_mode( ). " not necessary
           lr_email->set_property(
               iv_attr_name 'E_MAIL'   " Component Name
               iv_value     ls_bapiemail-e_mail ).
           lr_email->set_property(
               iv_attr_name 'EMAIL_SRCH'   " Component Name
               iv_value     ls_bapiemail-e_mail ).
           lr_email->set_property(
               iv_attr_name 'VALIDFROMDATE'   " Component Name
               iv_value     '19000101' ).
         ENDIF.
*& send all changes to BO layer
         lr_core->modify( ).
*& get the implicitly created global transaction
         lr_transaction lr_core->get_transaction( ).
*& save and commit your changes
         lr_transaction->save( ).
         lr_transaction->commit( ).
         EXIT.
       ENDWHILE.
     CATCH: cx_crm_genil_general_error,
            cx_root.
   ENDTRY.
ENDMETHOD.

Regards,

Amber Badam

Accepted Solutions (1)

Accepted Solutions (1)

navn_metts
Active Participant
0 Kudos

Hi,

Can you check this function module. " BAPI_BUPA_ADDRESS_CHANGE".


You can update the email id using this function module by passing the required data.


Br,

Navn

Answers (2)

Answers (2)

navn_metts
Active Participant
0 Kudos

Hi,

Please check if save() method is returning true or false.

IF ( lr_transaction->save( ) ) EQ 'X'.

lr_transaction->commit( ).

else.

lr_transaction->rollback( ).

endif.


If the save() method is returning false then check the order_save badi checck_before_save method.


check the condition which is raising raise do_not_save exception.


Br,

Navn

dharmakasi
Active Contributor
0 Kudos

Hi Amber,

You can use dynamic query object "BuilHeaderAdvancedSearch" instead of simple query object ( 'BuilHeaderSearch' ).. Once you get the result entity you can update email id in corresponding address entity.

And also check in debug mode at the line    CHECK lr_email IS BOUND. if this is not bound then you have to create a new entity and then set the email value to it.

Modify instead of check lr_email is bound, add below code,

if lr_email is bound.

set email id to the entity.

else.

lr_adrs->create_related_entities( iv_relation_name = 'BuilAddressEMailRel' ).

then set the email id value to the entity.

endif.

Regards,

Dharmakasi.

former_member192561
Participant
0 Kudos

Hi Dharmakasi,

Does it really matter, if the entity is fetched from dynamic query or a simple query ?

As I need to update the existing email address, lr_email has always a value . Strange enough, though I lock the parent entity and also address entity, it does not register the changes.

I.e. I see the changes in the entities of Transaction. However these changes does not have flag as changed .

Thank you.

Amber Badam