SAP Process Automation, Workflow, DMS: Streamlining Data Entry Tasks

When it comes to manual, repetitive work such as data entry, SAP Process Automation  

This solution builds upon the work in a previous blog post from Gunter Albrecht about SAP Process Automation: Read website data and update MS Excel file. Specifically, we will be using SAP Workflow and SAP Document Management Service (DMS) to provide extra visibility into this process and create additional ease of access to the file.

This SAP Process 

Here is an overview of the end to end process. This solution uses 3 different SAP services. The steps and their respective services are as follows:

  1. Using SAP Process Automation: Read data from a website and update an Excel file
  2. Using SAP Process Automation: Upload the file to DMS
  3. Using SAP Process Automation: Start an SAP Workflow instance to prompt the user to review the updated file
  4. Using SAP Workflow Management and SAP Process Automation: User approves or rejects changes made and an SAP Process Automation API Trigger is immediately called to shift the file in DMS

Here is a walk through of the solution.

technical%20architecture

technical architecture

For the sake of brevity, I will skip the steps talked about in the previous blog, and move directly to step 2 from the technical architecture.

Uploading the file to SAP Document Management Service

Before we are able to call DMS’ API to upload the file, we need to get the access token. We use Process Automation’s Custom script and Web Service tools to make the request for the token as follows.

Create a Custom script with the following code, this script will be fed as input to the Web Service.

let callParameters = { grant_type: "client_credentials"
}; var wsCallData = { resolveBodyOnly : true, method: 'POST', url: oauthUrl, searchParams: callParameters, headers: { 'Accept': 'application/json', 'Authorization': 'Basic ' + oauthBase64Credentials, 'Content-Type': 'application/json' }, body: ""
};
return wsCallData;

WS%20for%20access%20token

WS for access token

Now, we can move on to making the API call to upload the file using the access token. There are two things to note here. Firstly, the wsObject returned from the previous API call needs to be parsed to JSON format, and then the access token must  be extracted. Secondly, the API call can only take a form-data body. We need to use a workaround in Process Automation’s custom script as FormData JavaScript object is not usable (at the time of writing).

// Prepare call to upload file to SAP DMS let oauthToken = JSON.parse(wsTokenData);
var callParameters = { }; var uploadMetadata = [ { name: 'cmisAction', value: 'createDocument' }, { name: 'propertyId[0]', value: 'cmis:name' }, { name: 'propertyValue[0]', value: 'Your_Filename_Here_' + Date.now() + '.xlsx' }, { name: 'propertyId[1]', value: 'cmis:objectTypeId' }, { name: 'propertyValue[1]', value: 'cmis:document' }, { name: '_charset', value: 'UTF-8' }, { name: 'filename', value: 'Your_Filename_Here.xlsx' }, { name: 'media', file: 'C:\\Temp\\Your_Filename_Here.xlsx',, type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }
]; var wsDocMgtmtObj = { resolveBodyOnly : true, metadataType: irpa_core.enums.request.metadataType.formData, metadata : uploadMetadata, method: 'POST', url: docMgtmCallUrl + '/browser/' + repositoryId + '/root/' + folderName, headers: { 'Accept': 'application/json', 'Authorization': 'Bearer ' + oauthToken.access_token, 'DataServiceVersion': '2.0' } };

As with the previous step, feed this custom script as input to a Web Service tool and let Process Automation handle the rest.

Create a Workflow to review changes to the file

Now that we have uploaded the file to DMS, let’s create a Workflow instance to notify a user that a review of the changes is required.

approval%20workflow

approval workflow

Below is the workflow approval form that is sent to the user to notify them of changes made to the file. The user will be able to access the file using the URL in the File Link box of the form. We also see an approve and reject button, which the user can use once the review is completed.

Approval%20request%20in%20SAP%20Workflow

Approval request in SAP Workflow

The file is originally in the Excel Workflow folder. At the click of the “Approve” or “Reject” buttons, the file will be shifted to either the “Excel Approved” or “Excel Rejected” folder respectively.

DMS%20folders

DMS folders

Connecting your Workflow and Process Automation

This is done through an API call from Process Automation to Workflow. Here you can find the Workflow API for Cloud Foundry. We will be using the API to create a new instance of the Workflow definition we created in the previous step.

As with the previous API calls from Process Automation, prepare the necessary details in a Custom script and use that as input to a Web Service. One thing to note here is that Workflow’s API allows us to provide a JSON body, thus making this step simpler.

var bodyContent = { "definitionId": "yourWorkflowDefinition", "context": { "fileName": fileName, "docID": docID, "token": oauthToken.access_token }
}; var bodyContentJson = JSON.stringify(bodyContent); var wsCallData2 = { resolveBodyOnly : true, method: 'POST', url: wfRestUrl + "/v1/workflow-instances", searchParams: callParameters, headers: { 'Accept': 'application/json', 'Authorization': 'Bearer ' + oauthToken.access_token, 'Content-Type': 'application/json' }, body: bodyContentJson
};

Create a new Process Automation API trigger to shift the file in DMS

For the next step, we are interested in shifting the file in DMS based on whether the user approves or rejects the changes made.

Workflow does not allow use to create custom API calls. Instead, it only allows us to call a Destination in the Business Technology Platform (BTP). This means that we need to create the custom API call in Process Automation, deploy it as a trigger, then create it as a Destination in BTP. This way, we will be able to shift the file in DMS through Workflow, by calling the Process Automation trigger.

Here is the SAP Process Automation documentation on adding an API Trigger, as well as a tutorial.

Connect the API trigger to Workflow via BTP Destinations

Create a destination in BTP and use this in the SAP Workflow Service task, “Trigger Process Automation to Move File to Folder”, as shown in the approval workflow diagram above.

destination%20in%20BTP%20for%20Process%20Automation%20trigger

destination in BTP for Process Automation trigger

To summarize, we have used SAP Process Automation, SAP Workflow and DMS to streamline a manual data entry task. SAP Process Automation shows great promise in delivering efficiency and improving productivity, and you can check the Road Map here for more information on the features being rolled out.

Credits

Thanks to Gunter Albrecht for his earlier work which this solution builds upon, as well as for providing guidance and help throughout the development of this solution. Thanks to Aditi Arora for her help and advice on writing this blog post.