Skip to Content
Technical Articles

Integrating SAP CP Document Management Service UI in the Fiori App

Background:

Last year at SAP Teched, I saw two interesting demos related to document & attachment services. One is the demo of SAP Attachment Service in S4HANA and the other is the document management service in the SAP Cloud platform environment.

I really liked those demos as they were showcasing the ease of using those services and how they offer a UI, which we can easily integrate them into ourFiori Apps. Of course, S4HANA attachment service is free as it is part of that suite and the other one, you have to purchase to use it 😉

 

Then I wrote a blog post about the attachment service and how to consume it.

https://blogs.sap.com/2019/12/16/attachment-service-to-your-rescue-in-s4hana-fiori-elements-using-reuse-components-gos-dms/

 

and now here I am writing about the SAP CP Document Management service. I am planning to write two blog posts, In the first one(this), I will show a simple use case of creating a repository and how to show that repository in a Fiori Application. In the second one, I will show how to integrate into a CAP application.

 

This Blog Post:

In this post I will show a step by step approach to integrate SAP CP Document Management service in an ui5 app, which uses a reuse ui5 component from document management service.

So no need of any coding to handle documents, just use that reuse component in any UI5 app to handle documents. This will be a very basic app and probably be considered as an Admin UI.

The end UI looks like below:

 

Help Links:

https://help.sap.com/viewer/f6e70dd4bffa4b65965b43feed4c9429/Cloud/en-US/27e742e062924d72a9f1cb94a8c8346c.html

 

Creating a Repository:

You can find the below steps in the help here.

Step 1: Create an Instance for the Document Management, Integration Option in the Service Market Place.

Step 2: Create a Service Key

Step 3: Get Access Token

Before this step, if you want to know more about OAuth token and stuff, I would recommend to go check out the videos of DJ Adams , that are part of Devtoberfest.

https://github.com/SAP-samples/sap-devtoberfest-2020/tree/master/topics/cloud-apis

 

First View the service key and note down the below data:

Token URL

uaa.url/oauth/token?grant_type=client_credentials

client secret

uaa.clientsecret

clientid

uaa.clientid

service url

endpoints.ecmservice.url/rest/v2/repositories

 

Now go to the postman and create a post request, give your service URL in the input field

Now Select Authorization type as “OAuth2.0” and click on get a new access token.

Provide the Token URL in the postman Access Token URL and clientid, client secret as well. Then click on the Request Token and then click “Use Token” Button.

 

Step 3: Create Repository

Now Select the Body and provide the below information and select, Raw – JSON.

{
  "repository": {
		"displayName": "SAP Community",
		"description": "SAP Community",
		"repositoryType": "internal",
		"isVersionEnabled":"true",
		"isVirusScanEnabled":"false",
		"skipVirusScanForLargeFile": "true",
		"hashAlgorithms":"None"
  }
}

 

Now click “Send” to create the repository. Then the repository will be created.

Step 4: Get the Folder ID and Repository ID

Now replace the URL: /rest/v2/repositories with /browser and change the request type to “GET”

 

You can get the repositoryId from the step3, now in this step, get the rootFolderId for the created repository and save it somewhere, which will be used in other steps.

 

Basic MTA Fiori Application

Step 1: Generate a Basic MTA Application

On the Welcome page, select Create Project From Template and select “SAP Fiori Freestyle Project”.

Go next and select the Cloud Foundry environment from drop down and Select SAP UI5 Application and click next.

Give a project name: (CommunityDMAdmin)

Standalone Approuter

Give the name for your html module(communitydmadminui5)

Authentication : Yes

Finish.

 

It would now generate a basic Fiori app that has authentication and stuff. Now let’s go and configure the Document Management UI in the Fiori Application.

 

Step 2: Update MTA.YAML

Let’s update the yaml file with the Document Management instance that we created in step 1.

In the resources section, add below

- name: sapcommunity_dm
  type: org.cloudfoundry.managed-service
  parameters:
    service: sdm
    service-plan: standard

 

and add this resource under the approuter(in the same yaml file) as dependency under “requires”, and add properties which has the destination.. It should like below finally.

- name: communitydmadmin-approuter
  type: approuter.nodejs
  path: communitydmadmin-approuter
  requires:
  - name: CommunityDMAdmin_html_repo_runtime
  - name: uaa_CommunityDMAdmin
  - name: sapcommunity_dm
    properties: 
      destinations: "[{\"name\": \"sdibackend\", \"url\": \"https://api-sdm-di.cfapps.sap.hana.ondemand.com\", \"forwardAuthToken\": true}]"
  parameters:
    disk-quota: 256M
    memory: 256M

 

Step 3: Update xs-app.json in the ui5 app

add the below route, this is used when the ui5 send a request to ecmservice to fetch the reuse ui5 component.

{
      "source": "^/comsapecmreuse.comsapecmreusedocumentTable/api(.*)$",
      "target": "$1",
      "authenticationType": "xsuaa",
      "service": "com.sap.ecm.reuse",
      "endpoint": "ecmservice"
    }

 

Step 4: add component usage in the manifest.json of the UI5 app

"sap.ui5": {
    ...
    "componentUsages": {
      "documentTable": {
        "name": "com.sap.ecm.reuse.documentTable",
        "settings": {
          "destinationPath": "/comsapecmreuse.comsapecmreusedocumentTable/api",
          "repositoryId": "<REPOSITORY_ID>",
          "objectId": "<FOLDER_ID>",
          }
        }
      },
     "resourceRoots": {
       "com.sap.ecm.reuse.documentTable": "./../comsapecmreuse.comsapecmreusedocumentTable/"
     },
   }

Replace the <REPOSITORY_ID> and <FOLDER_ID> with the one we have noted in the previous steps

 

Step 4: add the component container to show the Document Management reuse UI

 

<Page id="page" title="Document Management Admin UI">
  <content>
    <core:ComponentContainer usage="documentTable" height="100%" async="false" manifest="true"/>
  </content>
</Page>

 

Step 5: Update the xs-app.json in approuter folder

go to xs-app.json in the approuter folder and add the welcome page

"welcomeFile": "/nscommunitydmadminui5/index.html",

nscommunitydmadminui5 is my ui5 app namespace without dots. If we do this, the approuter url will automatically open the ui5 app when we open it.

 

Buid and Deploy to SAP CP CF

Right click on the MTA.YAML file and select build MTA.

Later right click on the file inside mta_archives folder and deploy (Make sure you are logged in to your sap cp ).

 

Run the app

Open the application from your SAP CP space and click the applicatin route to open the UI5 App.

 

 

GIT URL

https://github.com/mahesh0431/CommunityDMAdmin

 

Next Steps

In the next blog post, I will show how to integrate this is a CAP Application. Link to Second Blog Post

Let me know your thoughts 🙂

 

Note: I am learning about SAP CP and it’s different services currently and All these are kind of new to me(mta yaml, xs-app.json ..,) and this is purely based on my learning experience, so let me know freely if I am doing any mistakes, so it will be a good learning for me 🙂

 

Thanks,
Mahesh

37 Comments
You must be Logged on to comment or reply to a post.
  • Hi Mahesh,

    I am getting the 415 Unsupported media type error when using POST Call. Below is the payload being used; I want to use Cloud as storage; hence using repository type as external.

    "repository": {
    "displayName": "Test Repository",
    "description": "Test Repository",
    "repositoryType": "external",
    "repositoryId": "Test_rep",
    "externalId": "Test_rep_ext"
    }

    Any idea; what is the issue here? The token I have successfully got.

     

    Regards,

    Karan

  • Hi Mahesh,

     

    I followed the steps as mentioned in the blog, however, when I execute the application, I am getting

    On further investigation, I found that "User does not have required scope"
    
    Any pointers for resolving the same. Thanks!
    /
    • You have to add the following two scopes to your user .

      SDM_User and SDM_Admin.
      To add the user scopes create a Role Collection in SAP Cloud Cockpit space where the app is deployed.
      Assign the above scopes to this Role Collection.
      And Finally assign the Role Collection to your user ID.
  • /
    Error
      • Hi Mahesh Kumar Palavalli

         

        I have the required roles assigned to the user. (I have followed this https://help.sap.com/viewer/f6e70dd4bffa4b65965b43feed4c9429/Cloud/en-US/2c99a03a2b7e42d5be44a7ef07c5f917.html)

        Even then, I am getting the same error. I think Abhinav has role issues - while mine is 404 and that's why I am stuck.

        Thanks & Regards,

        Sai Dhawal Phaye

    • This issue might might be because of routes not defined properly or you are not using the proper service instance of Document Management Integration Option to onboard your repositories.

       

      • To resolve issues for routes:

      Make sure if the route is defined in sapui5 module then mention the destinationPath: property in manifest.json as

      destinationPath : /comsapecmreuse.comsapecmreusedocumentTable/api

       

      route in ui5 module as

      {
        routes: [
          ...
          {
            "source": "^/comsapecmreuse.comsapecmreusedocumentTable/api/(.*)$",
            "target": "$1",
            "authenticationType": "xsuaa",
            "service": "com.sap.ecm.reuse",
            "endpoint": "ecmservice"
          },
          ...
        ]
      }

      If the route is defined in approuters xsapp.json then destinationPath: property in manifest.json as

      destinationPath : /api

      route in approuters xsapp.json as

      {
        routes: [
          ...
          {
            "source": "^/api/(.*)$",
            "target": "$1",
            "authenticationType": "xsuaa",
            "service": "com.sap.ecm.reuse",
            "endpoint": "ecmservice"
          },
          ...
        ]
      }
      • To resolve issue for not using proper service check if the service instance used to onboard repositories is the same one used for using integrating the Reuse UI . Check in mta.yaml

      Needs to be modified if the service instance is created with a different name

      - name: sdm-instance
      	  type: org.cloudfoundry.managed-service
      	  parameters:
            service: sdm
            service-plan: standard   	
      
  • Hi Mahesh,

    I followed your blog and try to execute the application I am getting the below error

    User%20does%20not%20have%20required%20scope

    User does not have required scope

    I checked your comments for above peoples.

    Could you please tell me what are the roles required to use document management service. Please mentioned  the roles in comments/

    Thanks.

    /
    User%20does%20not%20have%20required%20scope
  • Hi Mahesh,

    App execution:

    App

    App

    I am getting this error in the console line:

    console

    console

    Is there any possibility that this app doesn't work without any item on the repository?

    Thanks in advance.

  • /
  • Hi Mahesh,

    works like a charm. Thanks a lot!

    Do you know if it is possible to change the folder (objectId) dynamicly?  With this approach every fiori app has to work on a specific root folder.

    Regards,

    Koray

    • If anyone is interested meanwhile I found a solution: After analyzing https://[mycorrespondingapprouter]/comsapecmreuse.comsapecmreusedocumentTable/Component.js I found out that I can navigate through folder programmictly using requestNavigationAndOpen function.

  • Hi Mahesh,

    you have to specify repositoryId and objectId in the manifest.json file. These IDs are different on a 3-level landscape (dev, test, prod). Meaning you have to change manifest.json for each enviroment before deploying mtar.

    Is there a way make this configurable using user provided services or yaml?

    Thanks and regards,

    Koray

    • Hi Koray,

      You can do ajax call to /browser  before you actually call the requestNavigationandOpen(). The browser call will return all the repository related info. Extract the RepositoryID and RootFolderId and pass it to requestNavigationAndOpen().This way will solve your hardcoding of Ids if you are using different landscapes and maintain a single codeline.

      Regards,

      Tapishnu

  • Hi Mahesh,

    I would say your blog is crisp and clear and nice explanation as well on YouTube.

    I have doubt -- once we are able to create these folders, is there is any way to give access to specific user for display/hide or edit. Any document visibility rules ?

    please do suggest if any solution in your mind, I thought of Business Rules but not sure about it.

    Regards,

    Abhijeet Kankani