on ‎2015 Feb 09 11:46 AM
Dear experts ,
I am using the following code to create a workflow item and later I am attaching a file, the system is showing the attachment is created but its not showing the attachement with the workitem.
here is the code
IF sy-subrc EQ 0.
CALL FUNCTION 'SWW_WI_ENABLE'
EXPORTING
wi_id = WORKITEMID
DO_COMMIT = 'X'
EXCEPTIONS
UPDATE_FAILED = 1
NO_AUTHORIZATION = 2
INVALID_TYPE = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'DEQUEUE_E_WORKITEM'
EXPORTING
MODE_SWWWIHEAD = 'E'
CLIENT = SY-MANDT
WI_ID = WORKITEMID
X_WI_ID = ' '
_SCOPE = '3'
_SYNCHRON = ' '
_COLLECT = ' '
.
ENDIF.
* LOOP AT files_tab
* INTO wa_files.
CALL FUNCTION 'ENQUEUE_E_WORKITEM'
EXPORTING
MODE_SWWWIHEAD = 'E'
CLIENT = SY-MANDT
WI_ID = WORKITEMID
X_WI_ID = ' '
_SCOPE = '2'
_WAIT = ' '
_COLLECT = ' '
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
data: l_retcode LIKE SY-SUBRC,
l_att_id type SWR_ATT_ID,
lt_msg type TABLE OF SWR_MESSAG.
CALL FUNCTION 'SAP_WAPI_ATTACHMENT_ADD'
EXPORTING
workitem_id = WORKITEMID
att_header = l_header
att_bin = l_xstring
do_commit = 'X'
IMPORTING
return_code = l_retcode
att_id = l_att_id
TABLES
message_lines = lt_msg.
IF sy-subrc EQ 0.
CALL FUNCTION 'SWW_WI_ENABLE'
EXPORTING
wi_id = WORKITEMID
DO_COMMIT = 'X'
EXCEPTIONS
UPDATE_FAILED = 1
NO_AUTHORIZATION = 2
INVALID_TYPE = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'DEQUEUE_E_WORKITEM'
EXPORTING
MODE_SWWWIHEAD = 'E'
CLIENT = SY-MANDT
WI_ID = WORKITEMID
X_WI_ID = ' '
_SCOPE = '3'
_SYNCHRON = ' '
_COLLECT = ' '
.
ENDIF.
Request clarification before answering.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
mike now i am trying to attach it as a seaprate object , can you please tell me what i should put in the input container becoz its giving me error, here is the code.
CALL FUNCTION 'SAP_WAPI_ATTACHMENT_ADD'
EXPORTING
workitem_id = WORKITEMID
att_header = l_header
att_bin = l_xstring
do_commit = 'X'
IMPORTING
return_code = l_retcode
att_id = l_att_id
TABLES
message_lines = lt_msg.
COMMIT WORK.
SWC_CREATE_OBJECT BO_SOFM 'SOFM' l_att_id.
SWC_SET_ELEMENT INPUT_CONTAINER 'SOFM' BO_SOFM.
Hello Safeer,
I meant in your WF-Task binding.Check your log, _ATTACH_OBJECTS should contain a reference to your attachment, and it should be object type SOFM. Usually this is automatically bound to the workflow steps, but if something has been overwritten or I don't know what, it may be worth trying to bind this explicitly.
Regards,
Mike
The log is accessible via the 'Log' button in the work item display.
The binding is accessible via the 'Binding' button in the step editor.
See screenshots you posted yesterday.
Vijay's posts also included screenshots of what an attachment should look like, and how to bind it explicitly.
Regards,
Mike
So from the timing it is clear what the problem is:
It looks like you are starting the WF and then adding the attachment. This means the WI has probably already been created by the time you add the attachment, or it is locked and is in process of creating the work item. Therefore WF doesn't bind the attachment, because it isn't there yet.
You can either start the WF by one of the internal FMs or classes that do allow attachments (Not sure why SAP don't let you do it in the WAPI), or you can add the attachment to the decision task instead of the workflow (probably easier). Use SAP_WAPI_GET_CHILD_WORKITEMS to determine the work item number, and then go from there.
Is there a reason for staring the WF directly? If you used events you could pass the attachments along as well...
Regards,
Mike
Mike , this workflow is form based , I am passing internal table into a container to populate the value in forms fields and based on approval and rejection further processing will start. its a simple workflow I am not using object type in it as I don't need. I also tried enque and deque function modules to check if the workitem locked but same result . can you tell me which other internal function I can use for it. thanks for your help.
I would suggest trying the WAPI route first for two reasons:
1. You're already using a WAPI to start the WF and it works. You'd have to replace that.
2. It's the SAP-supported way...
3. It's easier
So after staring the WF, use SAP_WAPI_GET_CHILD_WORKITEMS to get the ID of the form task and add the attachment there. It should then bind automatically back to the WF once the task is completed.
Regards,
Mike
Great, glad we got there in the end.
Two suggestions: I would add a check to ensure the step is the one you want. TASK ID should be TS...whatever. Use that as your basis for finding the step.
Second, just in case of synchronization issues, I would put the get child items bit into a loop, if unsuccessful then WAIT UP TO 2 SECONDS and try again, maybe 30 times before failing (one minute).
Regards,
Mike
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.