Skip to Content
0
Former Member
Apr 13, 2010 at 06:19 AM

How to tigger an action and save it?

659 Views

Hi All,

can you please help me in tiggering an action.

the below code is posted by jonas and in debugging i found that it is working fine but it is not saving.if it is saved then the issue is solved.pls can anyone help me.

Is there any FM or Class to save it.

&----


*& Report Z_TRIGGER_ACTION * &----

*& The program should trigger the Action *& 'Z_FORLANGNING_1' used to create a follow-up *& transaction from an existing *contract.

&----


REPORT z_trigger_action.

INCLUDE crm_direct.

DATA lv_guid_ref TYPE crmt_object_guid.

DATA lv_context TYPE REF TO cl_doc_context_crm_order.

DATA lv_toolbar TYPE boolean.

DATA lv_manager TYPE REF TO cl_manager_ppf.

DATA lt_context TYPE ppftctxtir.

DATA lt_trigger TYPE ppfttrgor.

DATA ls_trigger TYPE ppfdtrgor.

DATA lt_action TYPE crmt_action_get_tab.

DATA ls_action TYPE crmt_action_get.

DATA lv_object TYPE REF TO object.

DATA lv_action TYPE REF TO cl_trigger_ppf.

DATA lv_status TYPE i.

DATA lt_objects_to_save TYPE crmt_object_guid_tab.

DATA ls_objects_to_save TYPE crmt_object_guid.

data : ls_guid type crmt_object_guid.

  • *Selection-screen

SELECTION-SCREEN BEGIN OF BLOCK 001.

*Object-ID for CRM Order Object

PARAMETERS p_obj_id TYPE crmt_object_id.

SELECTION-SCREEN END OF BLOCK 001.

********************************************************

  • Get GUID for CRM Order Object

SELECT SINGLE guid FROM crmd_orderadm_h INTO lv_guid_ref WHERE object_id = p_obj_id.

*********************************************************

  • 1. context create

CALL FUNCTION 'CRM_ACTION_CONTEXT_CREATE'

EXPORTING iv_header_guid = lv_guid_ref

iv_object_guid = lv_guid_ref

IMPORTING ev_context = lv_context

EXCEPTIONS no_actionprofile_for_proc_type = 1

no_actionprofile_for_item_type = 2

order_read_failed = 3

OTHERS = 4.

IF sy-subrc NE 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 RAISING error_occurred.

ENDIF.

  • 2. action deterimne

CALL FUNCTION 'CRM_ACTION_DETERMINE'

EXPORTING iv_header_guid = lv_guid_ref

iv_object_guid = lv_guid_ref

iv_context = lv_context

iv_for_toolbar_only = lv_toolbar

iv_no_detlog = true.

  • 3. get actions from ppf manager

lv_manager = cl_manager_ppf=>get_instance( ).

INSERT lv_context INTO TABLE lt_context.

CALL METHOD lv_manager->get_active_triggers

EXPORTING it_contexts = lt_context

IMPORTING et_triggers = lt_trigger.

  • 4. fill exporting parameters

LOOP AT lt_trigger INTO ls_trigger.

ls_action-guid = ls_trigger->read_guid( ).

ls_action-def = ls_trigger->get_ttype( ).

ls_action-text = cl_view_service_ppf=>get_descrp_for_dropdown( io_trigger = ls_trigger ).

INSERT ls_action INTO TABLE lt_action.

ENDLOOP.

  • 5 get actions from object services

CLEAR ls_action.

READ TABLE lt_action INTO ls_action WITH KEY def = 'ZCREATE_MULTI_LETTERS'.

IF sy-subrc = 0.

ls_guid = lv_guid_ref.

CALL METHOD ca_trigger_ppf=>agent->if_os_ca_persistency~get_persistent_by_oid

EXPORTING i_oid = ls_action-guid

RECEIVING result = lv_object.

lv_action ?= lv_object.

ENDIF.

  • 6 execute action

CALL METHOD lv_action->set_is_inactiv( space ).

CALL METHOD lv_action->execute

RECEIVING rp_rc = lv_status

EXCEPTIONS empty_medium_reference = 1

empty_appl_reference = 2

locked = 3

document_is_locked = 4

inactive = 5

startcondition_not_true = 6

OTHERS = 7.