Sending multiple attachment in user decision step of workflow
By Lokesh Tripathi, Infosys
document describes how to send multiple attachments in the user decision step of
User can see multiple attachments and based on that take the necessary required
method would be helpful in business processes where user wants to introduce
approval step before processing or accepting any finance report or other
User will execute the custom
report/transaction that will trigger the workflow (we can associate starting
event also to this workflow).
Workflow will send mail having multiple attachments to SAP Inbox as a user
Based on user decision rest logic would happen.
adding attachments in the user decision steps method EVENT_RAISED of interface IF_SWF_IFS_WORKITEM_EXIT needs to be
implemented and it is used as a Function Exit in the user decision step.
Go to SE24, implement method EVENT_RAISED of interface IF_SWF_IFS_WORKITEM_EXIT
ZTEST_WFATTACH is created for the same.
method code for inserting attachments needs to be implemented (Please use below
code for the same)
First check whether
workflow container already have any attachments or not to avoid any
the workflow work item Id
CALL METHOD IM_WORKITEM_CONTEXT->GET_WORKITEM_ID
RE_WORKITEM = LV_ID.
CALL METHOD IM_WORKITEM_CONTEXT->GET_WI_CONTAINER
RE_CONTAINER = LV_CONTAINER.
* Read attachment to confirm that there is no duplication
CALL METHOD LV_CONTAINER->GET
NAME = '_ATTACH_OBJECTS'
VALUE = LV_ATTACH.
IF LV_ATTACH IS INITIAL.
If there are no prior
attachments then identify the folder id based on sy-user
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
OWNER = SY-UNAME
REGION = 'B'
FOLDER_ID = LV_FOLDER_ID.
In this scenario we are converting spool output to PDF and attaching the same
PDF in the user decision step
Give spool number in LV_SPOOL field
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
NO_DIALOG = ''
PDF_DESTINATION = 'X'
PDF_BYTECOUNT = LA_BYTE_COUNT
PDF = GT_PDF
ERR_NO_ABAP_SPOOLJOB = 1
ERR_NO_SPOOLJOB = 2
ERR_NO_PERMISSION = 3
ERR_CONV_NOT_POSSIBLE = 4
ERR_BAD_DESTDEVICE = 5
USER_CANCELLED = 6
ERR_SPOOLERROR = 7
ERR_TEMSEERROR = 8
ERR_BTCJOB_OPEN_FAILED = 9
ERR_BTCJOB_SUBMIT_FAILED = 10
ERR_BTCJOB_CLOSE_FAILED = 11
OTHERS = 12.
LOOP AT GT_PDF INTO LWA_PDFLINE.
ASSIGN LWA_PDFLINE TO <L_XLINE> CASTING.
CONCATENATE PDF_XSTRING <L_XLINE>
INTO PDF_XSTRING IN BYTE MODE.
* Create and set document
IT_SOLIX_TAB1 = CL_DOCUMENT_BCS=>XSTRING_TO_SOLIX
LV_DATA-OBJ_NAME = 'Test Sending Attachments'.
LV_DATA-OBJ_DESCR = 'Attachment 1'.
LV_DATA-OBJ_LANGU = SY-LANGU.
LV_DATA-SENSITIVTY = 'P'.
LV_DATA-DOC_SIZE = LA_BYTE_COUNT.
CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
FOLDER_ID = LV_FOLDER_ID
DOCUMENT_DATA = LV_DATA
DOCUMENT_TYPE = 'PDF'
DOCUMENT_INFO = WA_DOCUMENT_INFO
CONTENTS_HEX = IT_SOLIX_TAB1
FOLDER_NOT_EXIST = 1
DOCUMENT_TYPE_NOT_EXIST = 2
OPERATION_NO_AUTHORIZATION = 3
PARAMETER_ERROR = 4
X_ERROR = 5
ENQUEUE_ERROR = 6
OTHERS = 7.
* Populate object type and object key for create an instance
LV_OBJTYPE = 'SOFM'.
LV_OBJKEY = WA_DOCUMENT_INFO-DOC_ID.
Creating SOFM object
CALL FUNCTION 'SWO_CREATE'
OBJTYPE = LV_OBJTYPE
OBJKEY = LV_OBJKEY
OBJECT = LV_SOFM
RETURN = LV_RETURN
NO_REMOTE_OBJECTS = 1
OTHERS = 2.
* Prepare for attaching the object to container
LV_OBJJECT-HEADER = 'OBJH'.
LV_OBJECT-TYPE = 'SWO'.
LV_OBJECT-HANDLE = LV_SOFM.
APPEND LV_OBJECT to TB_OBJ.
Similarly prepare other attachments and append their details to tb_obj
Finally send the attachment details in the task container
CALL METHOD LV_TAKS_CONTAINER->SET
NAME = '_ATTACH_OBJECTS'
VALUE = TB_OBJ.
* Commit the changes
CALL METHOD IM_WORKITEM_CONTEXT->DO_COMMIT_WORK.
Click here to continue...