Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
nabheetscn
Active Contributor
878
PS: Demo video at the end

Wow I am back again with my next rant of using more than one SAP Cloud platform service. This time it is SAP Cloud business rules and OCR API’s which can be further linked to the Cloud Workflow via this blog. This freedom of consuming different services, bringing them together to create some magic is actually awesome.

High Level Scenario Details


We will be making a hybrid application which will read basic invoice image via OCR API’s and trigger configured Business rules based on data got from the image. The business rules will determine whether the invoice will be posted directly or will internally trigger workflow approval and to whom.



We can use the business rules also in the workflow design I thought of using it here as of now. High level Business Rule






















Company Code Amount Workflow Approval Needed Approver
COMPA Less than 1000 No No
COMPA Greater than 1000 Yes <My Id>


 

 

Technology Stack used



  • SAP Cloud Platform Business Rules

  • SAP Cloud Platform OCR API’s

  • Ionic/Angular for Hybrid App Development


 

SAP Cloud Business Rules and OCR usage


I have referred this wonderful blog by archana.shukla to Activate the business rule service and Overview of business rules blog by muralidaran.shanmugham2 for creation of Business rules. You can find all the details in these blogs, just to conclude Business rules is more or less like BRF+ in Cloud.

Sample code for Angular HTTP Post call for OCR API


var data = new FormData();
data.append('files', $event.target.files[0], $event.target.files[0].name);
let headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('APIKey', this.sapcp.apikey);
xhr.send(data);
this.http.post("https://sandbox.api.sap.com/ml/ocr/ocr", data, {
headers: headers
})
.subscribe(data => {
console.log(data);
}, error => {
console.log("Oooops!");
console.log(error);
});

Sample code for Angular HTTP GET/POST call for Business Rules


var headers = new Headers();
headers.append('X-CSRF-Token', 'Fetch');
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Basic <base64 username:password>');
this.http.get("https://bpmrulesruntimebpm-<userid>trial.hanatrial.ondemand.com/rules-service/v1/rules/xsrf-token", {
headers: headers
})
.subscribe(data => {
data.headers.forEach((value, key) => {
if (key == "x-csrf-token") {
this.sapcp.xtoken = value[0];
}
});
var data1 = [{
"__type__": "Input",
"Bukrs": this.sapcp.bukrs,
"Amount": this.sapcp.amount
}];
headers = new Headers();
headers.append('X-CSRF-Token', this.sapcp.xtoken);
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Basic <base64 username:password>');
this.http.post("https://bpmrulesruntimebpm-<userid>trial.hanatrial.ondemand.com/rules-service/v1/rules/invoke?rule_service_name=NabheetRule::NabheetRuleService", data1, {
headers: headers
})
.subscribe(data => {
console.log(data);
this.loading.present();
}, error => {
console.log(error);
});
}, error => {
console.log(error);
});

Business Rule Settings Done for the demo



Demo



Challenges & Some Random Thoughts



  • OCR Service Effectiveness is something which i see needs to be worked upon. Sometimes the words were not properly recognized. It might be the font size was less but i was still expecting it to work as other public platforms were able to read.

  • Since SAP has moved towards Cloud Platform, it makes sense to get Payment Gateways also on boarded.

  • Exploring ABAP CDS view with Business Rules is something which is on my to do list next


Feel Free to provide your feedback, open to all ears.Sample Hybrid App Code can be found here.
9 Comments
Labels in this area