cancel
Showing results for 
Search instead for 
Did you mean: 

How to manually add a comment entry to a user decision step?

Sreenith
Participant

Hi ,

Like we add attachments to user decision step in workflow , i need to add a comment entry which was created as a note in request screen comment section.

Using code shown below i am only able to add comments as a text file in attachment section.

Let me know if any issues in below code

*Add comments from request screen to workitem
DATA: lv_atthdr TYPE swr_att_header,
lv_return_code TYPE sy-subrc,
lv_wid TYPE swr_struct-workitemid,
lv_att_id TYPE swr_att_id,
lv_str TYPE string.
* CLEAR: lt_obj.
* construct attachment header
IF ls_wfh-reason IS NOT INITIAL.
lv_atthdr-file_type = 'T'.
lv_atthdr-file_name = 'Request comments by' && '' && ls_wfh-userid.
lv_atthdr-file_extension = 'TXT'.
lv_atthdr-language = sy-langu.
lv_str = ls_wfh-reason.
lv_wid = ls_wfh-wid.
CALL FUNCTION 'SAP_WAPI_ATTACHMENT_ADD'
EXPORTING
workitem_id = lv_wid
att_header = lv_atthdr
att_txt = lv_str
document_owner = ls_wfh-userid
language = sy-langu
* do_commit = ' '
comment_semantic = 'X'
IMPORTING
return_code = lv_return_code
att_id = lv_att_id.

**& Creating sofm object
CALL FUNCTION 'SWO_CREATE'
EXPORTING
objtype = 'SOFM'
objkey = CONV swo_typeid( lv_att_id-doc_id )
IMPORTING
object = lo_sofmn
EXCEPTIONS
no_remote_objects = 1
OTHERS = 2.
IF sy-subrc = 0.
*& Prepare for attaching the object to container
ls_obj-header = 'OBJH'.
ls_obj-type = 'SWO'.
ls_obj-handle = lo_sofmn.
APPEND ls_obj TO lt_obj[].
ENDIF.
ENDIF.

IF lt_obj IS NOT INITIAL.
* *& Finally send the attachment details in the task container
TRY.
CALL METHOD lo_container->set
EXPORTING
name = '_ATTACH_OBJECTS'
value = lt_obj[].
CATCH cx_swf_cnt_container .
RAISE EXCEPTION TYPE cx_swf_ifs_workitem_exit_error.
ENDTRY.
ENDIF.

*& Commit the changes
CALL METHOD im_workitem_context->do_commit_work.

mchrista
Participant
0 Kudos

For simply adding a comment to a step in SAP Workflow, your code seems fine.

Probably, you just need to set < do_commit = 'X' > in order to persist the document. I call it with commit and it works fine for me.

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

File name was changed from

lv_atthdr-file_name = 'Request comments by' && '' && ls_wfh-userid.

to

lv_atthdr-file_name = 'User Comments'.

After this comment is appearing with 'workflow-system's comment