Read decision note for a task action from MyInbox

If a workflow task get’s approved or rejected in the MyInbox it’s sometimes necessary to maintain an justification. This justification aka decision note can be stored as a variable in the general workflow container and can be passed to different workflow steps/workitems. Through that it is possible to read the decision note at a later point at time. For example, for sending an mail to the user with the outcome of his request including the justification from the approver.

Store the decision note as an element in the workflow container

Create an element in the workflow container to be able to store the decision note. As data type use the BOR object type SOFM.

Bind your workflow container element against the user decision step. Binding from user decision step to workflow container. This way you store the decision note, which was created by the step, in the general workflow container.

If you want to access the decision note in a specific step just bind it. Binding from workflow container to step. Therefore create an element in the task container of the step. This way the decision note can be accessed.

Read the decision note from the workflow container through abap code

To read out the note you just need to pass the workitem id to the following method read_decision_note. That’s it.

Definition

  class-methods READ_DECISION_NOTE
    importing
      !IV_WIID type SWW_WIID
    exporting
      !EV_DECISION_NOTE type STRING .

Implementaiton

  METHOD read_decision_note.
    DATA: lt_container              TYPE swrtcont,
          lv_container_value        TYPE swc_value,
          lv_return_code            TYPE sysubrc,
          lv_document_id            TYPE so_entryid,
          lt_attachment_txt_content TYPE  TABLE OF solisti1.

*--- read the workitem container to access the decision note
    CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'
      EXPORTING
        workitem_id      = iv_wiid
      IMPORTING
        return_code      = lv_return_code
      TABLES
        simple_container = lt_container.

    lv_container_value = VALUE #( lt_container[ element = 'DECISION_NOTE' ]-value OPTIONAL ).

    CHECK lv_container_value IS NOT INITIAL.

    CONDENSE lv_container_value.
    lv_document_id = lv_container_value+5(34). "is there a better way? we couldnt find one...

*--- read the sofm document and export the plain text
    CALL FUNCTION 'SO_DOCUMENT_READ_API1'
      EXPORTING
        document_id    = lv_document_id
      TABLES
        object_content = lt_attachment_txt_content.

    CONCATENATE LINES OF lt_attachment_txt_content INTO ev_decision_note SEPARATED BY cl_abap_char_utilities=>cr_lf.

  ENDMETHOD.

Leave a Reply

Your email address will not be published. Required fields are marked *