Skip to Content
Technical Articles

SAP Conversational AI + S4HANA Cloud → ‘A Fantabulous Combination’

Hello Guys,

Welcome to Part 2 of the series SAP Conversational AI Overview & Build your first BOT.

In this blog post, I’ll be touching the area, which I believe most of you have been waiting with bated breath.

SAP Conversational AI + S4HANA Cloud

At the end of this post, you’ll be able to pull records/status from your S4HANA Cloud System by just chatting with your bot, and you won’t even have to log in to your S4HC system.

Sounds cool…. right!! ?

Before diving directly into the integration part, let me make a few points about S4HANA Cloud.

S4HANA Cloud integrates with any other system using APIs. For every Business Context like Purchase Order, Sales Order, Purchase Requisition, etc. SAP has provided a set of whitelisted APIs which are listed at SAP API Business Hub.

At the time of writing this blog post, SAP has released 365 APIs for S4HANA Cloud.

Now a question arises in mind, what if I need to use my custom data or have a custom API with customized data. Here comes into action the two beneficial objects which SAP calls Custom CDS Views and Custom Business Objects. Both of these data objects can be exposed as custom APIs for consumption.

To summarize, we have the following 3 methods to integrate with S4HANA Cloud:

  • Using standard whitelisted APIs
  • Creating custom CDS views and exposed as API
  • Creating custom business objects and exposed as API

For the sake of simplicity and understanding, we’ll be working on a use case that involves Custom Business Objects(CBO).

The whole use case consists of 3 parts:

  1. Creating a Custom Business Object in S4HC and exposing as API.
  2. Developing a nodeJS web server that is deployed on SAP Cloud Platform – Cloud Foundry environment. This web server acts as a middleware between CAI and S4HC.
  3. Adding intents and skill to your bot.

Part 1 – Creating CBO in S4HC

Step 1 – Login to your S4HC system and open app Custom business objects.

Step 2 – Create a new CBO with the name ‘NEW_MATERIALS.’

Make sure to check the below-highlighted properties of CBO.

 

Add the following fields, this CBO can hold the data for new materials which can be added manually and finally Publish the CBO.

 

Step 3 – Once the CBO is published and UI is generated.

Click on the Go to Generated UI link and add a few entries into the CBO.

 

 

Step 4. Now we need to expose the created CBO as an API for consumption outside the S4HANA system. This process involves a few steps like

  • Create a communication user
  • Create a communication system
  • Create a communication scenario
  • Create a communication arrangement

Create a communication user using the app ‘Maintain Communication User.’

Create a communication system using the app ‘Communication System.’

Now under the ‘Users for Inbound Communication’ section, assign the communication user created in the previous step and save.

 

Create Custom Communication Scenario using the app ‘Custom Communication Scenario.’

Now add the CBO, which we created in Step 2  as the inbound service and publish.

Now got to the communication arrangement tab and create a new arrangement.

Assign the communication system to the arrangement and save the communication arrangement.

Now our custom data service is ready.

Part 2 – Develop a Node.js webserver

Step 1 – Create a nodejs application and deploy it on SAP Cloud Platform – Cloud Foundry environment.

This nodejs application will interact with the custom Odata service using which we can access the S4 HANA  Cloud system.

const request = require('request')
const express = require('express')
const bodyParser = require('body-parser')

var app = express()
app.use(bodyParser.json())

app.post('/getmaterialdetails', (req, res) => {
	const material = req.body.conversation.memory.material.raw
	const url =
		'https://myXXXXXX-api.s4hana.ondemand.com/sap/opu/odata/sap/YY1_NEW_MATERIALS_CDS/YY1_NEW_MATERIALS?$filter=MaterialNumber eq \'' + material +
		'\'&$format=json'
	request.get(url, (error, response, body) => {
		if (error) {
			res.json({
				replies: [{
					type: 'text',
					content: 'Material Not Found'
				}]
			})
		} else {
			var temp = JSON.parse(body)
			res.json({
				replies: [{
					type: 'text',
					content: 'For material ' + material + ' details are: '
				},{
					type:'text',
					content: 'Material Description : '+temp.d.results[0].MaterialDescription +'\n Quantity :'+temp.d.results[0].Quantity_V
				} ],
			})
		}
	}).auth(<Communication User>, <Password>)
})

 

Step 2 – Deploy the nodejs application on the SAP Cloud Platform.

Step 3 – Use the deployed application URL with the proper path as a webhook of skill in SAP CAI.

 

Part 3 – Create intent and skills in CAI

Step 1 – Create an intent with certain expressions for fetching the details of a particular material from the S4HC system.

 

Step 2 – Specify the entity for each expression, as shown below.

Step 3 – Create skill with trigger conditions as below.

Step 4 – Specify the requirements and save the material number in bots memory.

Step 5 – Add webhook as the actions in the skill and provide the Nodejs webserver URL with the correct path.

 

Now you can test your bot.

You can verify the details from S4 HANA Cloud System.


Upcoming topics in this series of the blog:

  •  SAP CAI + S4HANA Cloud + Whatsapp = A marvelous user experience!

Stay tuned for more upcoming fantastic stuff.

 

I hope you all have enjoyed this blog post, and I’ve been able to make myself clear. Please let me know your thoughts, doubts in the comment section below, and if you enjoyed, please like and share.

Wishing excellent health and safety to all of you and your friends & families.

 

3 Comments
You must be Logged on to comment or reply to a post.
  • Hello Shubhkarman,

    I would like to thanks for the nice blog, Could  you Please explain more on  how to create a node js application and deploy it on SAP Cloud Platform – Cloud Foundry environment.Thanks  in  advance.

     

      • Hi Subhkaram,

        Thank you for this excellent blog. I tried all possible options to deploy node.js app with above code and given article but my app is not getting deployed via CLI on my trail cloud foundry account and it is crashing. I tried simple "hello world" application and it works just fine. Not sure what could be the reason but it is giving me crash messages. I tried updating your script for variable such as below with my cloud S4 HANA account url and also updated communication user and password but nothing works.

        https://myXXXXXX-

        while using CF push command do deploy application, it is giving below messages. Can you please suggest any solution? I'm not sure what I'm missing.

        2021-01-04T10:12:04.27-0600 [PROXY/1] OUT Exit status 137
        2021-01-04T10:12:04.69-0600 [CELL/1] OUT Cell 9d4b115f-ea58-43e8-ba55-118dea4fb61d successfully destroyed container for instance 550e3cdf-966d-4427-6de8-1171
        2021-01-04T10:12:37.73-0600 [CELL/1] OUT Cell 07fcd1e7-7d31-49d5-ba9a-ac10fc6ecc99 creating container for instance 09753ced-990f-4963-5ffc-9a8e
        2021-01-04T10:12:37.74-0600 [CELL/0] OUT Cell 0688f4d2-0524-4c22-a8e5-48f432aca8ee creating container for instance 514775a6-e45e-4f86-42fb-2d90
        2021-01-04T10:12:38.33-0600 [CELL/0] OUT Cell 0688f4d2-0524-4c22-a8e5-48f432aca8ee successfully created container for instance 514775a6-e45e-4f86-42fb-2d90
        2021-01-04T10:12:38.38-0600 [CELL/1] OUT Cell 07fcd1e7-7d31-49d5-ba9a-ac10fc6ecc99 successfully created container for instance 09753ced-990f-4963-5ffc-9a8e
        2021-01-04T10:12:38.59-0600 [CELL/1] OUT Downloading droplet...
        2021-01-04T10:12:38.67-0600 [CELL/0] OUT Downloading droplet...
        2021-01-04T10:12:39.07-0600 [CELL/1] OUT Downloaded droplet
        2021-01-04T10:12:39.07-0600 [CELL/1] OUT Starting health monitoring of container
        2021-01-04T10:12:39.12-0600 [CELL/0] OUT Downloaded droplet
        2021-01-04T10:12:39.12-0600 [CELL/0] OUT Starting health monitoring of container
        2021-01-04T10:12:39.88-0600 [APP/PROC/WEB/1] OUT > myapp@0.0.1 start /home/vcap/app
        2021-01-04T10:12:39.88-0600 [APP/PROC/WEB/1] OUT > node start.js
        2021-01-04T10:12:39.98-0600 [APP/PROC/WEB/0] OUT > myapp@0.0.1 start /home/vcap/app
        2021-01-04T10:12:39.98-0600 [APP/PROC/WEB/0] OUT > node start.js
        2021-01-04T10:12:40.05-0600 [APP/PROC/WEB/1] OUT Exit status 0
        2021-01-04T10:12:40.14-0600 [APP/PROC/WEB/0] OUT Exit status 0
        2021-01-04T10:12:45.57-0600 [CELL/0] OUT Cell 0688f4d2-0524-4c22-a8e5-48f432aca8ee stopping instance 514775a6-e45e-4f86-42fb-2d90
        2021-01-04T10:12:45.57-0600 [CELL/0] OUT Cell 0688f4d2-0524-4c22-a8e5-48f432aca8ee destroying container for instance 514775a6-e45e-4f86-42fb-2d90
        2021-01-04T10:12:45.59-0600 [API/17] OUT Process has crashed with type: "web"
        2021-01-04T10:12:45.61-0600 [API/17] OUT App instance exited with guid 69ca2316-03d5-4176-8864-68924f1bd150 payload: {"instance"=>"514775a6-e45e-4f86-42fb-2d90", "index"=>0, "cell_id"=>"0688f4d2-0524-4c22-a8e5-48f432aca8ee", "reason"=>"CRASHED", "exit_description"=>"Codependent step exited", "crash_count"=>4, "crash_timestamp"=>1609776765567473698, "version"=>"85b5f7fe-f929-42e6-954c-c06132f75339"}
        2021-01-04T10:12:45.70-0600 [CELL/1] OUT Cell 07fcd1e7-7d31-49d5-ba9a-ac10fc6ecc99 stopping instance 09753ced-990f-4963-5ffc-9a8e
        2021-01-04T10:12:45.70-0600 [CELL/1] OUT Cell 07fcd1e7-7d31-49d5-ba9a-ac10fc6ecc99 destroying container for instance 09753ced-990f-4963-5ffc-9a8e
        2021-01-04T10:12:45.73-0600 [API/19] OUT Process has crashed with type: "web"
        2021-01-04T10:12:45.73-0600 [PROXY/0] OUT Exit status 137
        2021-01-04T10:12:45.75-0600 [API/19] OUT App instance exited with guid 69ca2316-03d5-4176-8864-68924f1bd150 payload: {"instance"=>"09753ced-990f-4963-5ffc-9a8e", "index"=>1, "cell_id"=>"07fcd1e7-7d31-49d5-ba9a-ac10fc6ecc99", "reason"=>"CRASHED", "exit_description"=>"Codependent step exited", "crash_count"=>4, "crash_timestamp"=>1609776765707060663, "version"=>"85b5f7fe-f929-42e6-954c-c06132f75339"}
        2021-01-04T10:12:45.90-0600 [PROXY/1] OUT Exit status 137
        2021-01-04T10:12:46.15-0600 [CELL/0] OUT Cell 0688f4d2-0524-4c22-a8e5-48f432aca8ee successfully destroyed container for instance 514775a6-e45e-4f86-42fb-2d90
        2021-01-04T10:12:46.29-0600 [CELL/1] OUT Cell 07fcd1e7-7d31-49d5-ba9a-ac10fc6ecc99 successfully destroyed container for instance 09753ced-990f-4963-5ffc-9a8e