cancel
Showing results for 
Search instead for 
Did you mean: 

Add Order Partner on Status Change.

dsdaraujo
Explorer
0 Kudos
322

Hello,

I hope someone can help me.

I have a requirement where I have to assign current user to a known partner function in open order in crm webclient, depending on status changing.

I created an implementation of badi CRM_ORDER_STATUS, and I'm trying to add the user as partner of order using BOL, as follows below, within method IF_EX_CRM_ORDER_STATUS~AFTER_CHANGE:

  DATA:

        lr_core               TYPE REF TO cl_crm_bol_core,

        lr_btorder            TYPE REF TO cl_crm_bol_entity,

        lr_btadminh           TYPE REF TO cl_crm_bol_entity,

        lr_partnerset         TYPE REF TO cl_crm_bol_entity,

        lr_partner_col        TYPE REF TO if_bol_entity_col,

        lv_partner            TYPE bu_partner,

        lr_partner            TYPE REF TO cl_crm_bol_entity,

        lr_partner_encontrado TYPE REF TO cl_crm_bol_entity,

        lv_partner_descr      TYPE string,

        lv_description_name   TYPE bu_descrip,

        lv_partner_str        TYPE string.

  TRY.

      lr_core = cl_crm_bol_core=>get_instance( ).

      lr_core->load_component_set( 'ONEORDER' ).

      lr_btorder = lr_core->get_root_entity( iv_object_name = 'BTOrder' iv_object_guid = is_status_wrk-guid ).

      lr_btadminh = lr_btorder->get_related_entity( 'BTOrderHeader' ).

      lr_partnerset = lr_btadminh->get_related_entity( 'BTHeaderPartnerSet' ).

      lr_partner_col = lr_partnerset->get_related_entities( iv_relation_name = 'BTPartnerAll' ).

      IF lr_partnerset->switch_to_change_mode( ) = abap_true.

        lr_partner = lr_partnerset->create_related_entity( iv_relation_name = 'BTPartnerAll' ).

          IF lr_partner->switch_to_change_mode( ) = abap_true.

            lv_partner_str = iv_partner.

            cl_crm_uiu_bt_partner=>get_partner_description( EXPORTING iv_partner      = lv_partner_str

                                                            IMPORTING ev_description  = lv_description_name ).

            lv_partner_str = lv_description_name.

            lr_partner->set_property( EXPORTING iv_attr_name = 'PARTNER_NO'       iv_value = <user partner_no> ).

            lr_partner->set_property( EXPORTING iv_attr_name = 'PARTNER_FCT'      iv_value = <my partner function> ).

            lr_partner->set_property( EXPORTING iv_attr_name = 'KIND_OF_ENTRY'    iv_value = 'A' ) .

            lr_partner->set_property( EXPORTING iv_attr_name = 'NO_TYPE'          iv_value = 'BP' ) .

            lr_partner->set_property_as_string( EXPORTING iv_attr_name = 'DESCRIPTION_NAME' iv_value = lv_partner_str ) .

            lv_partner_str = <my partner function description>.

            lr_partner->set_property_as_string( EXPORTING iv_attr_name = 'PARTN_FCT_DESCR' iv_value = lv_partner_str ) .

            cl_crm_bol_core=>get_instance( )->modify( ).

          ENDIF.

          lr_partner_col->add( lr_partner ).

          cl_crm_bol_core=>get_instance( )->modify( ).

        ENDIF.

    CATCH cx_root.

  ENDTRY.

My problem is that the partner is shown on BTPARTNER assignment block (I'm using SRQM_INCIDENT_H BSP component), but when I click on save button, the partner disappears.

I don't know what else can I do to achieving this. Please, anybody can help?

Accepted Solutions (1)

Accepted Solutions (1)

stephenjohannes
Active Contributor
0 Kudos

You shouldn't be using BOL code inside of that BADI in the first place.  You are going to need to use the one order FM's to add the partner to make it work instead.  My brain right now is drawing blank on which FM to use, but I think CRM_PARTNER_MAINTAIN_SINGLE_OW or CRM_PARTNER_CREATE_OW is the approriate call.

The other issue is that I'm not 100% certain that your BADI will have the correct timing for your requirement, but you can try it out and see how it works.

Take care,

Stephen

dsdaraujo
Explorer
0 Kudos

Thank you, Stephen.

Could you please explain why not using BOL inside that BADI? Shouldn't we use BOL inside any BADI?

stephenjohannes
Active Contributor
0 Kudos

The BADI you are using sits beneath the BOL layer.  You are actually in a different layer of CRM when you use that BADI and not in the UI layer.  The BOL layer for business transactions or "one order" invokes the very code you might be trying to use.  It also leads to performance issues and infinite loops(possible) when writing BOL code in the one-order layer.

Take care,

Stephen

Answers (0)