Consume SAP Document Management using @cap-js/sdm plugin

Estimated read time 10 min read

In this blog post I am going to write how can you store the attachments(documents) in to SAP Document management repository using SAP Document Management CAP Plugin.

This plugin provides an UI within it which helps the user to attach ‘ n’ number of attachments and save all these attachments in a single click of Save in the SAP Document management repository using CAP application on Business technology platform. The node package that provides the functionality for Document Management is @cap-js/sdm plugin. The source code of this plugin can be found in the repository. https://github.com/cap-js/sdm

The SDM CAP plugin provides out-of-the-box asset storage and handling. To use it, all we need to do is to extend the domain model by using the predefined aspect called Attachments, that is delivered as part of @cap-js/sdm plugin.

Preview: The SDM CAP plugin also add the facets required to display the attachment section on the Object page. This attachment sections uses the control sap.m.upload.UploadSetwithTable.

This plugin enables cmis operations like create Document,Rename,getContentStream and delete document.

User provides the repository Id where the attachments should get stored in package.json under cds.env.requires as below 

“sdm”: {
“settings”: {
“repositoryId”: “<repository-Id>”
}
}

  Follow the below steps to store your documents in SAP Document management repository with an inbuilt UI without the users developing their own UI and just extending their CAP entity with attachments aspect.

1. Users who can want to start fresh with  CAP and want to try out a basic CAP application with SAP Document Management CAP Plugin

Consider a simple bookshop application and users of this application wants to store the cover page, book invoice, softcopy of book etc in to SAP Document Repository then just start creating a book shop CAP application by following the below steps.

 

Step 1: Initialise the CAP Project

Initialise the cap project using the command cds init in the root directory of the project folder.

Execute the command npm install to install the dependencies.

You can now start the cap server using the command cds watch. This will start the cap server on http://localhost:4004.

The service would now be empty without any entities defined.

 

Step 2: Adding Sample CDS Model

To add the sample cds model, execute the command cds add tiny-sample in the terminal.

This will add the entity definition in the db folder and add some sample data in the data folder.

 

namespace my.bookshop;

entity Books {
key ID : Integer;
title : String;
stock : Integer;
}

In the srv folder, the book entity is exposed. I have modified the generated code to remove the @readonly and add enabled draft handling.
 
using my.bookshop as my from ‘../db/data-model’;

service CatalogService {
entity Books as projection on my.Books;
annotate Books with @odata.draft.enabled;
}

Execute the command cds watch to run the service.

 

 

Step 3: Add the UI5 Application

Open the Fiori Application generator from the menu view -> command palette -> Fiori: Open Application Generator.

In the wizard, select the list report template.

 

 

Map the data source to the local cap project and select the catalog service.

 

Select the books entity.

 

 

Enter the project details and click on finish. This will add the ui5 application in the app folder.

 

 

In the generated project, update the path of the service in the manifest.json. 

 

 

Note:To be able to use the Fiori uploadTable feature, you must ensure 1.121.0/ 1.122.0/ ^1.125.0 SAPUI5 version is updated in the application’s index.html

Execute the command cds watch to run the service. Now you should be able to see the ui5 application served.

 

 

The list report page and object page of the application as of now should be as below.

 

 

 

Follow the below blog to set up the approuter which redirects the user via xsuaa fetching the user info and generating token enabling authentication and authorization which is required when you want to test locally

https://community.sap.com/t5/technology-blogs-by-members/test-your-cap-nodejs-applications-with-authentication-locally/ba-p/13417243

If you want to run your application in BTP then just add auth as “jwt” in package.json and deploy the app.

Once the above steps are done jump to point 2 to see how to add SAP Document Management plugin to your bookshop application.

 

2.  If you have your own CAP application deployed on Business Technology platform and just want to use SDM CAP plugin to enable users to store the documents in to SAP Document management Repository.

 

Add the SAP Document Management Plugin.

To add the SAP Document Management plugin, execute the following command from the terminal.

 

npm add @cap-js/sdm
 

In the db folder add a new schema file, let’s name it attachment.cds and the following to extend the Book entity with the composition to attachment aspect from the attachment plugin.

Here you should add extend for your entity as the below example is for bookshop one.

 

using {my.bookshop as my} from ‘./data-model’;
using {Attachments} from ‘@cap-js/sdm’;

extend my.Books with {
attachments : Composition of many Attachments;
}

 

And that’s it!!. Now you can deploy the application to Business technology platform and store your attachments in to SAP Document Management Repository.

 

Features supported

Create ‘n’ attachments with single click of Save Entity.Delete ‘n’ added attachmentsDelete Entity which deletes all the linked attachments within entityRename a document nameRead the attachment(download/preview the attachment based on browser support).

 

Hope this blog helps you in storing your documents to SAP Document Management Repository from CAP Application.

 

 

 

 

 

 

​ In this blog post I am going to write how can you store the attachments(documents) in to SAP Document management repository using SAP Document Management CAP Plugin.This plugin provides an UI within it which helps the user to attach ‘ n’ number of attachments and save all these attachments in a single click of Save in the SAP Document management repository using CAP application on Business technology platform. The node package that provides the functionality for Document Management is @cap-js/sdm plugin. The source code of this plugin can be found in the repository. https://github.com/cap-js/sdmThe SDM CAP plugin provides out-of-the-box asset storage and handling. To use it, all we need to do is to extend the domain model by using the predefined aspect called Attachments, that is delivered as part of @cap-js/sdm plugin.Preview: The SDM CAP plugin also add the facets required to display the attachment section on the Object page. This attachment sections uses the control sap.m.upload.UploadSetwithTable.This plugin enables cmis operations like create Document,Rename,getContentStream and delete document.User provides the repository Id where the attachments should get stored in package.json under cds.env.requires as below “sdm”: {
“settings”: {
“repositoryId”: “<repository-Id>”
}
}  Follow the below steps to store your documents in SAP Document management repository with an inbuilt UI without the users developing their own UI and just extending their CAP entity with attachments aspect.1. Users who can want to start fresh with  CAP and want to try out a basic CAP application with SAP Document Management CAP PluginConsider a simple bookshop application and users of this application wants to store the cover page, book invoice, softcopy of book etc in to SAP Document Repository then just start creating a book shop CAP application by following the below steps. Step 1: Initialise the CAP ProjectInitialise the cap project using the command cds init in the root directory of the project folder.Execute the command npm install to install the dependencies.You can now start the cap server using the command cds watch. This will start the cap server on http://localhost:4004.The service would now be empty without any entities defined. Step 2: Adding Sample CDS ModelTo add the sample cds model, execute the command cds add tiny-sample in the terminal.This will add the entity definition in the db folder and add some sample data in the data folder. namespace my.bookshop;

entity Books {
key ID : Integer;
title : String;
stock : Integer;
}In the srv folder, the book entity is exposed. I have modified the generated code to remove the @readonly and add enabled draft handling. using my.bookshop as my from ‘../db/data-model’;

service CatalogService {
entity Books as projection on my.Books;
annotate Books with @odata.draft.enabled;
}Execute the command cds watch to run the service.  Step 3: Add the UI5 ApplicationOpen the Fiori Application generator from the menu view -> command palette -> Fiori: Open Application Generator.In the wizard, select the list report template.  Map the data source to the local cap project and select the catalog service. Select the books entity.  Enter the project details and click on finish. This will add the ui5 application in the app folder.  In the generated project, update the path of the service in the manifest.json.   Note:To be able to use the Fiori uploadTable feature, you must ensure 1.121.0/ 1.122.0/ ^1.125.0 SAPUI5 version is updated in the application’s index.htmlExecute the command cds watch to run the service. Now you should be able to see the ui5 application served.  The list report page and object page of the application as of now should be as below.   Follow the below blog to set up the approuter which redirects the user via xsuaa fetching the user info and generating token enabling authentication and authorization which is required when you want to test locallyhttps://community.sap.com/t5/technology-blogs-by-members/test-your-cap-nodejs-applications-with-authentication-locally/ba-p/13417243If you want to run your application in BTP then just add auth as “jwt” in package.json and deploy the app.Once the above steps are done jump to point 2 to see how to add SAP Document Management plugin to your bookshop application. 2.  If you have your own CAP application deployed on Business Technology platform and just want to use SDM CAP plugin to enable users to store the documents in to SAP Document management Repository. Add the SAP Document Management Plugin.To add the SAP Document Management plugin, execute the following command from the terminal. npm add @cap-js/sdm In the db folder add a new schema file, let’s name it attachment.cds and the following to extend the Book entity with the composition to attachment aspect from the attachment plugin.Here you should add extend for your entity as the below example is for bookshop one. using {my.bookshop as my} from ‘./data-model’;
using {Attachments} from ‘@cap-js/sdm’;

extend my.Books with {
attachments : Composition of many Attachments;
} And that’s it!!. Now you can deploy the application to Business technology platform and store your attachments in to SAP Document Management Repository. Features supportedCreate ‘n’ attachments with single click of Save Entity.Delete ‘n’ added attachmentsDelete Entity which deletes all the linked attachments within entityRename a document nameRead the attachment(download/preview the attachment based on browser support). Hope this blog helps you in storing your documents to SAP Document Management Repository from CAP Application.        Read More Technology Blogs by SAP articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author

+ There are no comments

Add yours