Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member197733
Contributor
Our SAP Experts are working really hard to deliver the upcoming SMB Summits' Hackathon. The main goal is to make SAP Business One and SAP Business ByDesign partners to built the Intelligent Enterprise for SMBs. From Chatbots to Mobile Apps passing by Blockchain and Voice Interfaces.

One of the so-called build blocks I am in charge regards the amazing AWS IoT Button. If you are not familiarised, this is a Cloud Programmable Dash Button. It is connected to the internet and its only function is to call a web-service upon pressed.

https://d1.awsstatic.com/IoT/assets/aws_iot_button.62b50cbaeae340c18aa411d87c86029e188caab0.png

So small yet so powerful


Don't get fooled by the simplicity. The possibilities are endless. For example, reordering services or products. Requesting a callback from a customer agent or a call for assistance button in a retail shop. Not to mention alerts notification systems and, of course, creating documents in SAP Business ByDesign or sending messages to SAP Business One.

Let's get it done


Pre-requisites are simple:
A SAP Business One System with Service Layer and/or a SAP Business ByDesign Tenant. You also need an AWS Account. Which for what we need is free of charge.

For the ByD case, we need to create a OData service to expose the Sales Order object. You can do it manually or import the model we shared previously.

Configuring the button:

You can follow the official guide to make configure your button using a computer. But I strongly advise using the AWS IoT Button Dev app, available on Google Play and on Apple Store.

Start by login into the app. And follow the instructions on the screen. The app will scan the button's bar code in order to configure all the required services and security certificate.



Next step, we want to make the button connect to the internet. So we turn it into a hotspot with its own wifi, connect to it using the password on the screen, and configure what Wifi network it should use.



Last part, we want to the button to call a web-service, but we haven't configured it any so far. Choose any of the NodeJS templates, e.g. Send Email (nodejs), provide the additional parameters (email address) and conclude the configuration.



At this point, your dash button is already configured. And if you press it you should receive an email. Now we are going to change the Lambda Function created by the app, to talk with SAP Business One and SAP Business ByDesign.

Head to my Github and clone or download the smbDashButton repository.


Compress all the files into a zip file. Make sure there is no folder structure in the zip. The root folder should contain all the files of the repository (and not a folder like smbDashButton-master, as when downloading a zip from GitHub)



Now go to the AWS Lambda cockpit and access your newly created function.



If you do not see your function, make sure to select the right AWS Region as on your app

Scroll down to the editor panel and choose "Upload a .zip file". Choose the previously created zip and click on save.


You will see the function code deployed. We just need to configure the environment variables for your case.

I explained in the comments of GitHub what is required for SAP Business One and for SAP Business ByDesign. So scroll down ao bit more set them accordingly:

.

Save it and Done!


Your button should be configured. And you have an example of a product agnostic solution built with a loosely coupled architecture.

A SINGLE press should call SAP Business One and send a Message to the specified user. a LONG  press will create a sales order in SAP Business ByDesign:

https://youtu.be/SetM9fnRTsU

Code Analysis


The code of this sample isn't tricky. Just consider the button will send a message with the following payload
{
"serialNumber": "GXXXXXXXXXXXXXXXXX",
"batteryVoltage": "xxmV",
"clickType": "SINGLE" | "DOUBLE" | "LONG"
}

 

With that, on index.js we decide what kind of action will be performed (B1 or ByD)
const B1SL  = require('./modules/b1ServiceLayer');
const BYD = require('./modules/bydOdata')

exports.handler = (event, context, callback) => {
console.log('Received event:', event);

switch (event.clickType) {
case 'SINGLE':
B1SL.PostMessage(callback)
break;
case 'LONG':
BYD.PostSalesOrder(callback)
break;
default:
break

}
};

Each module is pretty self explanatory. Let's take the SAP Business One Example

The PostMessage Function try to Connect To Service Layer. If that It's successful, then a message is posted.
function PostMessage(options, callback) {

Connect(function (error, resp) {
if (error) {
console.error("Can't Connect to Service Layer");
console.error(error);
} else {
console.log("Connected Successfully, lets send a message");
var options = {
headers: {
'Cookie': resp.cookie
}
};
options.body = JSON.stringify({
RecipientCollection: [{
SendInternal: "tYES",
UserCode: process.env.B1_USER_ENV || "manager"
}],
Subject: "Dash Button Pressed",
Text: "This is a message from your dash button"
})
//Make Request
SLPost(options, "/Messages", function (error, response, bodymess) {
if (error) {
console.error("Error Sending SL Message \n" + error );
} else {
console.log("Message Sent successfully!")
}
})
}
});

Let me know what do you think! Remember, you will find much more samples and cool innovations like that in the SMB Summits Hackathon. This is THE event to go if you are a SAP Business One or SAP Business ByDesign Partner.

So post your comments below or ping me on Twitter.

Cheers!