cancel
Showing results for 
Search instead for 
Did you mean: 

How to call BuildProcessAutomation's TriggerAPI from RAP

asahi_naoya
Explorer
0 Kudos
206

I'm trying to call the BuildProcessAutomation TriggerAPI from RAP, but it's not working.
Could you please tell me how to solve this problem or give me some sample code?

The call was successful when using the Development in Classic ABAP method, but when I coded in the determination on Save section, an error occurred at runtime.
I would like to use the Development in ABAP RESTful Application Programming Model (RAP) method.

See below

Development in ABAP RESTful Application Programming Model (RAP) | SAP Help Portal

 

Test Code(on determination on Save section)

CONSTANTS: wf_definitionId   TYPE if_swf_cpwf_api=>cpwf_def_id_long  VALUE 'us10.xxxxxxxxx.testonefield.test_one_field',
           wf_retention_days TYPE if_swf_cpwf_api=>retention_time VALUE '30',
           consumer          TYPE string VALUE 'DEFAULT'.

**** Define the structure of the payload
 types:begin of context,
   field1 type string,
 end of context.

  TYPES: BEGIN OF ty_context,
    context TYPE context,
  END OF ty_context.

 TYPES: BEGIN OF ty_payload,
   start_event TYPE ty_context,
 END OF ty_payload  .

TRY.
* Get the API of workflow
  DATA Wf_handle     TYPE sysuuid_c32.
  DATA(lo_cpwf_api) = cl_swf_cpwf_api_factory_a4c=>get_api_instance( ).

**convert workflow data to be passed in json format
  data lv_context type ty_context.
  lv_context-context-field1 = 'test_value'.

  DATA(context_json) = lo_cpwf_api->get_start_context_from_data(
        iv_capital_letter  = abap_false
*        it_name_mapping    = VALUE #( ( abap = 'CONTEXT' json = 'CONTEXT' ) )
        iv_data = lv_context
        ).


*trigger workflow
  MODIFY ENTITIES OF i_cpwf_inst
      ENTITY CPWFInstance
      EXECUTE registerWorkflow
      FROM VALUE #( (
*                      %key = '<a UUID which is mandatory for mass enabled callers>'
                      %param-RetentionTime = 30
                      %param-PaWfDefId = wf_definitionId
*                      %param-CpWfDefId = ''
*                      %param-CallbackClass = '<Callback class for final state handling>'
                      %param-Consumer = 'DEFAULT'
                    ) )
     MAPPED DATA(mapped_wf)
     FAILED DATA(failed_wf)
     REPORTED DATA(reported_wf).

  MODIFY ENTITIES OF i_cpwf_inst
      ENTITY CPWFInstance
      EXECUTE setPayload
      FROM VALUE #( (
*                      %key-CpWfHandle = '<required key (UUID) of the CPWF instance>'
                      %key-CpWfHandle = mapped_wf-cpwfinstance[ 1 ]-CpWfHandle
                      %param-context =  context_json ) )
      MAPPED mapped_wf
      FAILED failed_wf
      REPORTED reported_wf.
 

 

Accepted Solutions (0)

Answers (0)