Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to trigger action on delegated object

samh
Explorer
0 Kudos

Hi,

I am new to BOPF, I have read through a lot of the information on SDN and have a query. I have a scenario where I need to trigger an action on a delegated object, the BO is /CPD/PWS_BO_MP and the delegated object is /BOBF/ATTACHMENT_FOLDER. What I need to do is when the BO /CPD/PWS_BO_MP is created, then create delegated object /BOBF/ATTACHMENT_FOLDER and trigger CREATE_FOLDER to create some attachment folders automatically.

I have read though to understand how to trigger an action, however this doesn't work on the delegated object directly. Having read is seems I have to do this via the main BO, however this blog post only really covers reading the delegated object, I haven't found a way to trigger an action on a delegated object yet.

Any tips or clues would be much appreciated.

Thanks,

Sam

1 ACCEPTED SOLUTION

samh
Explorer
0 Kudos

Got this working in the end by debugging via /BOBF/TEST_UI - only thing I haven't figured out is which constant relates to the action GUID in iv_act_key as I cannot find one which maps to this.

   DATA: lr_srv_mgr    TYPE REF TO /bobf/if_tra_service_manager.

   DATA: lr_tra_mgr    TYPE REF TO /bobf/if_tra_transaction_mgr.

   DATA: lv_mp_guid        TYPE /bobf/conf_key.

   DATA: ls_key            TYPE /bobf/s_frw_key.

   DATA: lt_key            TYPE /bobf/t_frw_key.

   DATA: lt_mp_data        TYPE /cpd/t_mp_hdr_k.

   DATA: lv_rejected       TYPE boole_d.

   DATA: lt_mod            TYPE /bobf/t_frw_modification.

   DATA: ls_parameters     TYPE /bobf/s_atf_a_create_folder.

   DATA: lt_failed_key     TYPE /bobf/t_frw_key.

   DATA: lt_failed_act_key TYPE /bobf/t_frw_key.

   DATA: lr_atf_hdr        TYPE REF TO /bobf/s_atf_root_k.

   DATA: lr_message        TYPE REF TO /bobf/if_frw_message.

   DATA: lr_change         TYPE REF TO /bobf/if_tra_change.

   DATA: lr_s_parameters   TYPE REF TO data.

   FIELD-SYMBOLS: <ls_mod> LIKE LINE OF lt_mod.

   FIELD-SYMBOLS <ls_key> LIKE LINE OF lt_key.

   TRY.

       "Get the project GUID

       CALL METHOD /cpd/cl_pws_ws_utility=>get_mp_guid_from_id

         EXPORTING

           iv_mp_id   = iv_mp_id

         RECEIVING

           rv_mp_guid = lv_mp_guid.

       IF lv_mp_guid IS INITIAL.

         RAISE invalid_id.

       ENDIF.

       "Get service manager

       lr_srv_mgr = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /cpd/if_mp_pws_bo_c=>sc_bo_key ).

       "Get transaction manager

       lr_tra_mgr = /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( ).

       "Retrieve the master project

       ls_key-key = lv_mp_guid.

       APPEND ls_key TO lt_key.

       CALL METHOD lr_srv_mgr->retrieve

         EXPORTING

           it_key       = lt_key

           iv_node_key  = /cpd/if_mp_pws_bo_c=>sc_node-mp_hdr

           iv_fill_data = abap_true

         IMPORTING

           et_data      = lt_mp_data.

       "Create the MP_ATTACH_FOLDER association

       CREATE DATA lr_atf_hdr.

       lr_atf_hdr->key = /bobf/cl_frw_factory=>get_new_key( ).

       lr_atf_hdr->parent_key = lv_mp_guid.

       lr_atf_hdr->root_key = lv_mp_guid.

       APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.

       <ls_mod>-node            = /cpd/if_mp_pws_bo_c=>sc_node-mp_attach_folder.

       <ls_mod>-change_mode     = /bobf/if_frw_c=>sc_modify_create.

       <ls_mod>-source_node     = /cpd/if_mp_pws_bo_c=>sc_node-mp_hdr.

       <ls_mod>-association     = /cpd/if_mp_pws_bo_c=>sc_association-mp_hdr-mp_doc_attachment.

       <ls_mod>-source_key      = lv_mp_guid.

       <ls_mod>-key             = lr_atf_hdr->key.

       <ls_mod>-data            = lr_atf_hdr.

       CALL METHOD lr_srv_mgr->modify

         EXPORTING

           it_modification = lt_mod

         IMPORTING

           eo_change       = lr_change

           eo_message      = lr_message.

       lr_message->get_messages( IMPORTING et_message = et_messages ).

       CHECK et_messages IS INITIAL.

       "Call the CREATE_FOLDER action

       CLEAR lt_key.

       APPEND INITIAL LINE TO lt_key ASSIGNING <ls_key>.

       <ls_key>-key = lr_atf_hdr->key.

       ls_parameters-name                = 'TEST'.

       ls_parameters-description_content = 'TEST'.

       GET REFERENCE OF ls_parameters INTO lr_s_parameters.

       CALL METHOD lr_srv_mgr->do_action

         EXPORTING

           iv_act_key           = '005056B650081ED699895101DE8780EC'

           it_key               = lt_key

           is_parameters        = lr_s_parameters

         IMPORTING

           eo_change            = lr_change

           eo_message           = lr_message

           et_failed_key        = lt_failed_key

           et_failed_action_key = lt_failed_act_key.

       lr_message->get_messages( IMPORTING et_message = et_messages ).

       CHECK et_messages IS INITIAL.

       CALL METHOD lr_tra_mgr->save

         IMPORTING

           eo_change   = lr_change

           eo_message  = lr_message

           ev_rejected = lv_rejected.

       lr_message->get_messages( IMPORTING et_message = et_messages ).

     CATCH /bobf/cx_frw.

       RAISE internal_error.

   ENDTRY.

3 REPLIES 3

samh
Explorer
0 Kudos

Got this working in the end by debugging via /BOBF/TEST_UI - only thing I haven't figured out is which constant relates to the action GUID in iv_act_key as I cannot find one which maps to this.

   DATA: lr_srv_mgr    TYPE REF TO /bobf/if_tra_service_manager.

   DATA: lr_tra_mgr    TYPE REF TO /bobf/if_tra_transaction_mgr.

   DATA: lv_mp_guid        TYPE /bobf/conf_key.

   DATA: ls_key            TYPE /bobf/s_frw_key.

   DATA: lt_key            TYPE /bobf/t_frw_key.

   DATA: lt_mp_data        TYPE /cpd/t_mp_hdr_k.

   DATA: lv_rejected       TYPE boole_d.

   DATA: lt_mod            TYPE /bobf/t_frw_modification.

   DATA: ls_parameters     TYPE /bobf/s_atf_a_create_folder.

   DATA: lt_failed_key     TYPE /bobf/t_frw_key.

   DATA: lt_failed_act_key TYPE /bobf/t_frw_key.

   DATA: lr_atf_hdr        TYPE REF TO /bobf/s_atf_root_k.

   DATA: lr_message        TYPE REF TO /bobf/if_frw_message.

   DATA: lr_change         TYPE REF TO /bobf/if_tra_change.

   DATA: lr_s_parameters   TYPE REF TO data.

   FIELD-SYMBOLS: <ls_mod> LIKE LINE OF lt_mod.

   FIELD-SYMBOLS <ls_key> LIKE LINE OF lt_key.

   TRY.

       "Get the project GUID

       CALL METHOD /cpd/cl_pws_ws_utility=>get_mp_guid_from_id

         EXPORTING

           iv_mp_id   = iv_mp_id

         RECEIVING

           rv_mp_guid = lv_mp_guid.

       IF lv_mp_guid IS INITIAL.

         RAISE invalid_id.

       ENDIF.

       "Get service manager

       lr_srv_mgr = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /cpd/if_mp_pws_bo_c=>sc_bo_key ).

       "Get transaction manager

       lr_tra_mgr = /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( ).

       "Retrieve the master project

       ls_key-key = lv_mp_guid.

       APPEND ls_key TO lt_key.

       CALL METHOD lr_srv_mgr->retrieve

         EXPORTING

           it_key       = lt_key

           iv_node_key  = /cpd/if_mp_pws_bo_c=>sc_node-mp_hdr

           iv_fill_data = abap_true

         IMPORTING

           et_data      = lt_mp_data.

       "Create the MP_ATTACH_FOLDER association

       CREATE DATA lr_atf_hdr.

       lr_atf_hdr->key = /bobf/cl_frw_factory=>get_new_key( ).

       lr_atf_hdr->parent_key = lv_mp_guid.

       lr_atf_hdr->root_key = lv_mp_guid.

       APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.

       <ls_mod>-node            = /cpd/if_mp_pws_bo_c=>sc_node-mp_attach_folder.

       <ls_mod>-change_mode     = /bobf/if_frw_c=>sc_modify_create.

       <ls_mod>-source_node     = /cpd/if_mp_pws_bo_c=>sc_node-mp_hdr.

       <ls_mod>-association     = /cpd/if_mp_pws_bo_c=>sc_association-mp_hdr-mp_doc_attachment.

       <ls_mod>-source_key      = lv_mp_guid.

       <ls_mod>-key             = lr_atf_hdr->key.

       <ls_mod>-data            = lr_atf_hdr.

       CALL METHOD lr_srv_mgr->modify

         EXPORTING

           it_modification = lt_mod

         IMPORTING

           eo_change       = lr_change

           eo_message      = lr_message.

       lr_message->get_messages( IMPORTING et_message = et_messages ).

       CHECK et_messages IS INITIAL.

       "Call the CREATE_FOLDER action

       CLEAR lt_key.

       APPEND INITIAL LINE TO lt_key ASSIGNING <ls_key>.

       <ls_key>-key = lr_atf_hdr->key.

       ls_parameters-name                = 'TEST'.

       ls_parameters-description_content = 'TEST'.

       GET REFERENCE OF ls_parameters INTO lr_s_parameters.

       CALL METHOD lr_srv_mgr->do_action

         EXPORTING

           iv_act_key           = '005056B650081ED699895101DE8780EC'

           it_key               = lt_key

           is_parameters        = lr_s_parameters

         IMPORTING

           eo_change            = lr_change

           eo_message           = lr_message

           et_failed_key        = lt_failed_key

           et_failed_action_key = lt_failed_act_key.

       lr_message->get_messages( IMPORTING et_message = et_messages ).

       CHECK et_messages IS INITIAL.

       CALL METHOD lr_tra_mgr->save

         IMPORTING

           eo_change   = lr_change

           eo_message  = lr_message

           ev_rejected = lv_rejected.

       lr_message->get_messages( IMPORTING et_message = et_messages ).

     CATCH /bobf/cx_frw.

       RAISE internal_error.

   ENDTRY.

cyclingfisch_
Active Contributor
0 Kudos

Hi Sam,

Did you try the approach described by Aiko Schmale in the blog post you linked to?

Try to get the action name with the help of the configuration.

You get the configuration object if you call /BOBF/CL_FRW_FACTORY=>GET_CONFIGURATION.

The configuration offers a method GET_ACT which returns an action key.

When you have the key of the action you can call it. The difference to Aiko's example is just that you use the object io_modify instead of io_read and there the method do_action.

Cheers,

Martin

0 Kudos

Hi Martin,

Many thanks, I have read the blog post again and it has all fallen into place now using the GET_CONTENT_KEY_MAPPING method of the configuration object to get the action key.

Thanks,

Sam