Skip to Content

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 to Activate the business rule service and Overview of business rules blog by Murali 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.

To report this post you need to login first.

9 Comments

You must be Logged on to comment or reply to a post.

  1. DJ Adams

    Nice post!

    Some random (very minor!) observations:

    • nice to see an Angular UI here
    • looking at the business rules, what if the invoice amount is exactly 1000? 😉
    • are you planning to share the app’s code (minus any authentication details) on e.g. Github?
    • I’m liking the retro “Bukrs” property name
    • it’s not necessary to send a Content-Type header in the GET request if you’re not sending a payload (which you’re not in the CSRF Fetch call)

    cheers!

    (1) 
    1. Nabheet Madan Post author

      Thanks DJ for the detailed feedback. You caught it bang on for 1000 nothing as was for demo. I actually liked this idea of uploading this and previous app’s code on github. Will upload and update the blog. How can we forget BUKRS 😂😂

       

      (1) 
  2. Jelena Perfiljeva

    Nice blog! This looks like something I’d be reading about 5 years down the line. 🙂 Right now I’m still going through 2009 blogs thinking “wow, we have this stuff in SAP?!”.

    Thanks for sharing! And BUKRS 4EVER! We should make t-shirts. 🙂

     

    (1) 
  3. Murali Shanmugham

    Thanks for sharing your experience. The OCR APIs are planned to be available 1805. So I hope its more stable. I was looking to build something similar on these lines for an eReceipt app 🙂

     

    (1) 
    1. Nabheet Madan Post author

      Thanks Murali. So many services cloud has offered sometimes i get confuse😂 but yes it has opened up infinite possibilties. I will say you should go ahead with your eReceipt app and share the experience with us, definatley we all will benefit from it.

       

      (0) 
  4. Hemachandan A S

    Thanks Nabheet and I’m currently in the building phase of a similar kinda solution so looking forward to hear more from you for the community also don’t forget to share the code for reference. 🙂

    Cheers

    Chandan

    (1) 

Leave a Reply