With SAP Netweaver Gateway, SAP delivers a great standard service for getting and processing SAP workflow tasks (/IWWRK/WFSERVICE).
In a recent situation I found out that the default behaviour of the service returns the description (body/message of the workflow task) ignoring new lines. It just concatenates the text in one long string.
Showing this on the client (a native iOS app in my case) does not look good. Luckily SAP provides some BADI's that can be implemented to alter the default behaviour.
ProblemLet's say you configured a workflow tasks using a large body with multiple lines:
If you look at this task in transaction SBWP, it displays as expected, with line breaks:
However, if you get the task description from the SAP Netweaver Gateway Service using the path WorkflowTaskCollection('<workitem_id>')?$expand=Description or WorkflowTaskCollection('<workitem_id>')/Description, new lines are lost and the description contains double spaces as wel. Here is the default behaviour in a native iOS app:
This looks terrible. So somehow I had to get the new lines on the client. Of course there are several solutions for this, but using a standard badi is the best way in my opinion.
SolutionI ended up by creating an implementation for badi /IWWRK/ES_WF_CUST_EXT_IB. This badi has the interface method MODIFY_WORKITEM:
As you can see, the method has changing parameters for the subject and the description of the task that is returned by the gateway service. So all I had to do is read the description text including new lines from the system and store it in the cv_description variable:
* Data declaration
DATA: lt_lines TYPE TABLE OF swr_txtlin.
DATA: lt_streamlines TYPE TABLE OF swr_txtlin.
DATA: lv_line TYPE swr_detlin.
* Read workitem description
CALL FUNCTION 'SAP_WAPI_WORKITEM_DESCRIPTION'
workitem_id = is_wi_details-wi_id
text_lines = lt_lines
stream_text_lines = lt_streamlines.
* Replace default description with description including new lines
LOOP AT lt_streamlines INTO lv_line.
CONCATENATE cv_description lv_line INTO cv_description SEPARATED BY space.
SHIFT cv_description LEFT DELETING LEADING space.