Skip to Content
0
Nov 10, 2010 at 01:41 PM

Deletion of 1:1 related BOL object

356 Views

Hi all,

I would like to change the BTSubjectSet_H and the underlying BTSubjectSingle of an One Order Opportunity object.

BOL Path:

BTOrder -> BTOrderHeader -> BTHeaderBOSSet -> BTSubjectSet_H -> BTSubjectSingle

Because my BTSubjectSet_H profile has to be changed - subject_profile is different for this Subject - I must delete this item, because the BOL model won't allow me to change key fields like the subject_profile. The difficulty here is that the BOL relationship between BTHeaderBOSSet and BTSubjectSet_H remains in the MANAGER_ENTRY of the BTHeaderBOSSet and the relation is 1:1.

So when I create a new BTSubjectSet_H, I get an Dupiclate record exception, even when I reread the BTHeaderBOSSet. Anyone with suggestions how to proceed?

Hereby the code example in the way it doesn't work (but I think it should).

REPORT ztest.

DATA: lr_core                            TYPE REF TO cl_crm_bol_core,
      lr_tx                              TYPE REF TO if_bol_transaction_context,
      lr_bol_order                       TYPE REF TO cl_crm_bol_entity,
      lr_bol_order_h                     TYPE REF TO cl_crm_bol_entity,
      lr_bol_bos                         TYPE REF TO cl_crm_bol_entity,
      lr_bol_subjectset                  TYPE REF TO cl_crm_bol_entity,
      lr_bol_subject                     TYPE REF TO cl_crm_bol_entity.

PARAMETERS: p_guid TYPE crmt_genil_object_guid.

lr_core = cl_crm_bol_core=>get_instance( ).

lr_core->start_up( 'BT' ).

lr_bol_order = lr_core->get_root_entity(
                 iv_object_name = 'BTOrder'
                 iv_object_guid = p_guid ).
lr_bol_order->lock( ).

lr_bol_order_h = lr_bol_order->get_related_entity( 'BTOrderHeader' ).

lr_bol_bos = lr_bol_order_h->get_related_entity( 'BTHeaderBOSSet' ).
lr_bol_subjectset = lr_bol_bos->get_related_entity( 'BTSubjectSet_H' ).
IF lr_bol_subjectset IS BOUND.
  lr_bol_subjectset->delete( ).
  lr_core->modify( ).
  lr_bol_bos->reread( ).
* This will get an Duplicate Rel message
  TRY.
      lr_bol_subjectset = lr_bol_bos->create_related_entity( 'BTSubjectSet_H' ).

    CATCH cx_crm_genil_duplicate_rel.
      BREAK-POINT.
* Here we are
  ENDTRY.
ENDIF.