How to handle attachments in SAP Cloud Platform Workflow
Many business processes have documents (or paperwork) like sales orders, deliveries, payments, reports, and other collected forms involved in the day-to-day operations. These documents pass across the different departments and/or people in a business process and could play a crucial role in the outcome of approval. Hence these documents should be readily available in the workflow for the approver to make an informed decision.
I have explained in one of my blogs on how to enable collaboration and document management capabilities in SAP Cloud Platform Workflow using SAP Jam. In that, I have described how multiple approvers can collaboratively approve a single document. However, if the use case is only to store documents (without a need for collaboration) and later access them in SAP Cloud Platform Workflow to support the decision-making process, then you have come to the right place. In this blog, I shall explain how to manage document in SAP Cloud Platform Workflow using the SAP Cloud Platform Document Service.
SAP Cloud Platform Document Service is an implementation of the CMIS standard and is the primary interface to a reliable and safe store for content on SAP Cloud Platform. It can store and manage unstructured and semi-structured data like documents, images, videos, presentations, and other files. The consumption of CMIS-enabled document repositories is easy using the Apache Chemistry libraries. Apache Chemistry provides libraries for several platforms to consume CMIS using Java, PHP, Python or .Net. Since the SAP Cloud Platform Document service API includes OpenCMIS Java library, applications can be built on SAP Cloud Platform that is independent of a specific content repository.
The digital documents required for an approval workflow are uploaded to SAP Document Service repository. The URL to access these documents is persisted in the workflow context. This URL can be used from the workflow task UI to access the available document. To persist the documents and access them later, we would need to build and deploy a java based proxy-bridge application. The objective of this application is to enable access to the document repository from an external application (like My Inbox or any SAPUI5 application accessed from Portal).
1. Create a document repository
Create a document repository in the subaccount area of SAP Cloud Platform Cockpit. You can refer to the help documentation for the detailed steps.
2. Deploy proxy-bridge application
Create and deploy a simple CMIS proxy-bridge java application in your SAP Cloud Platform subaccount. Refer to the help documentation on how to achieve this.
3. Access CMIS URL
Once you have deployed & started the proxy-bridge application, note down the URL of the app. For my app (with name dbrRepoService) the cockpit shows the following URL:
To access the CMIS repository, add /cmis/json to the end of the application URL and execute that in a browser.
4. Access the document repository
Now that you have successfully accessed the CMIS URL to get the repository details, copy the repositoryId property and append it to the URL and follow it with /root to access your repository, as shown in the image below.
You have now accessed the document repository to get the metadata of all the objects that are available in the repository. If you do not see any output for this API, then it is probably because your document repository is empty. You can follow step 4 & 5 of this help document to create a sample HTML5 application to upload documents to the repository.
5. Access a particular document from the repository
Observe that for each document uploaded to the repository you have an Object node that contains different properties of the particular content. To access a specific document from the repository, add the value of the property cmis:name.value to the CMIS repository root URL as shown in the image below.
So, the URL to access a particular document would be:
6. Accessing the document from SAP Cloud Platform Workflow task UI
Now that we are aware of how to locate a document using the CMIS repository URL, the same can be persisted in the workflow context and later accessed from a task UI. In the below image you can see that under the Attachments tab, a link to the document is provided. On click of the link, you can open the document in a new tab/window or in an iframe or any native controls like PDFViewer.
Though it might seem simple to add a link in the task UI, keep in mind that the CMIS URL needs to be accessed via SAP Cloud Platform destination and all URLs are routed through Fiori Launchpad (since MyInbox is accessed from FLP). If I need to access the CMIS URL from the task UI, then URL would look like below:
Hence the CMIS URL with the above format was persisted in the workflow context.
Finally, you should also add a route in the neo-app.json of the task UI that maps the ‘destinationMapping’ in the above URL (/destinations/CMIS) to the actual destination in SAP Cloud Platform (CMIS).
Points to Note
- The documents uploaded to the document service repository should contain a unique name. If there is a chance that more than one document could have the same name, then it is necessary to generate a unique file name.
- If you have multiple task UIs that requires to access the CMIS URL, then you don’t need to add the route in neo-app.json of each application. Instead, you can add the route to the neo-app.json of one SAPUI5 application and use that applicationID across.
- SAP Cloud Platform Document Service is a repository to store your data (documents), and it does not come with any user interface to manage documents and requires you to build a custom user interface for the same. You could optionally use SAP Document Center to overcome this hurdle.
- In this blog, I have explained how you can use SAP Cloud Platform Document Service for storing the document and accessing the same from an SAP Cloud Platform Workflow. The same approach can also be used to access a document from any document management system.
I believe that this blog shows you how simple it is to handle attachments in SAP Cloud Platform Workflow. Do try it out bearing in mind that the same principle can be used to attach a document from any other document management system.