Wednesday, August 31, 2011

Triggering a workflow from abap

Last week’s post was about creating a workflow on a custom object.

In a normal situation, when using standard objects in workflow, you subscribe your workflow on existing events on existing standard objects.

These events are raised in standard coding, at the right time.

When using custom objects, you should also raise the event in custom coding, so for instance after saving an instance of your custom object to the database, you should raise the CREATED event.

Raising an event on a BOR object can be easily done with the following simple ABAP code:

DATA it_cont TYPE TABLE OF swcont.
DATA it_event_id TYPE swedumevid-evtid.

CALL FUNCTION 'SWE_EVENT_CREATE'
  EXPORTING
    objtype = [your object type]
    objkey = [your instances key]
    event = [your event]
  IMPORTING
    event_id = it_event_id
  TABLES
    event_container = it_cont
  EXCEPTIONS
    objtype_not_found = 1
                   OTHERS = 2.


IF it_event_id IS NOT INITIAL.
  COMMIT WORK.
ENDIF.

All workflows that start on that event will start.

If you are working with foreign custom objects (for instance custom objects in an ERP system), add the coding to a remote enabled function module, and call this from the remote system.

No comments:

Post a Comment