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: 
lukas_schoeneberger70
Participant

Intro


This blog post is part of the SAP Conversational AI Tutorial Challenge 2021  and this tutorial describes how to set up a chatbot with the main purpose of creating Purchase  Requisitons (PRs) in Ariba via Ariba Open APIs. Since this bot uses various APIs, only the most important implementation points are described in detail.

 

Problem Description


In case an employee wants to create a Purchase Requistion (PR) in SAP Ariba, he needs to log into Ariba, navigate towards the catalog, search, select, provide more details and submit the requisition. If the item he wants to order is a non-catalog item, the employee creates a free-text PR and also needs to select a material group – which can become cumbersome.

After placing the PR, the PR also needs to be approved – which is yet another task that may benefit from automation.

 

Solution


A chatbot is placed within MS Team and provides the possibility of placing a PR for catalog as well as non-catalog items. For catalog items, the chatbot, via an API call, provides the user with a list of items the user is looking for.  After the chatbot has collected all required information, a web service is used to place the PR in Ariba. When creating a non-catalog item, the chatbot calls a Machine Learning service in order to receive the material group for the submitted free-text purchase requisition.

Furthermore, a user can view all his pending approvals and get a link to the current document in Ariba.

 

You will learn



  • How to build a basic conversation flow with the purpose of placing/approving a purchase requisition

  • How to embed a chatbot in MS Teams

  • How to call an Ariba webservice to create a purchase requisition (catalog & non-catalog)

  • How to connect to an Microsoft Azure Machine Learning endpoint (send collected free-text purchase requisition & receive predicted commodity code)

  • How to get pending approvals from Ariba via a web service


 

Prerequisites



  • MS Teams

  • SAP CAI Basics

  • SAP Ariba System

  • Microsoft Azure Account (works with free trial)

  • SAP Cloud Platform Integration (just to convert XML, you can also use a different tool)


Note: You do not necessarily need to have all of these system in order to benefit from parts of this tutorial. E.g. if you are interested only in connecting to Microsoft Azure Machine Learning, then you do not need Teams or Ariba.

 

Implementation Guide


To implement the bot in MS Teams, refer to this blog post.

For the navigation of the tasks, a lot of quick replies were used.


Skills Overview


In the greetings skill, a description of what the bot is capable of doing should be inserted as well as the options of “Create PR” and “Approve PR” as buttons leading to the respective skills.

 

Create PR


Within the Create PR section, within another skill, provide the options of “Search Item” and “Non-Catalog Item” as buttons leading to the respective skills. A memory value is set to distinguish between the items and use the same skills for different items.


Select type of PR



Purchase Requisition of a Catalog Item


The first skill provides the user, based on the user input, a list of available items from Ariba. The skill has two requirements, the number of units the user wants to order and the item itself.  After fulfilling both requirements, the bot provides a list of the search results. For the bot to be able to display the result, a first API gets the validation token and a second service consumes the Catalog Content API from Ariba. In order to be able to filter the items, the filter value from the user input is added to every attribute in the array.


Filter added to the API response and the list for the items


 

“all” memory-field:
  {
"contents": [
{{#eachJoin api_service_response.default.body.contents}}
{
"ShortName": "{{escape ShortName}}",
"Price": "{{[Price.Amount]}}",
"SupplierPartId": "{{SupplierPartId}}",
"LeadTime": "{{LeadTime}}",
"Filter": "{{../memory.Item1-Filter.value}}"
}
{{/eachJoin}}
]
}

 

Script for the item list:
{
"type": "list",
"content": {
"elements": [
{{#eachJoin memory.all.contents}}
{{#gt (occurrences (lowercase ShortName) Filter) 0}}
{
"title": "{{ShortName}}",
"imageUrl": "",
"subtitle": "Price: {{Price}} €, delivery time: {{LeadTime}} day(s)",
"buttons": [
{
"title": "Order Part No. {{SupplierPartId}} ",
"value": "{{SupplierPartId}}",
"type": "postback"
}
]
}
{{/gt}}
{{/eachJoin}}
]
}
}

Afterwards, the user has the option to order an item in the list, to search again or to place a free-text purchase requisition. If the user selects an item from the list, the SupplierPartId is handed over to the next skill.

After selecting the item, the user may edit the item, add another item or edit the PR, i.e. change the title and add an overall comment.


Catalog PR Options


 

The process for the overall comment in the PR or a comment for an item is the same. A first a skill asks the user for his comment, a second skill converts the input into a memory field (e.g. {{memory.Item1-Comment}}) (you can find more details on how to save the entire user response in memory in the Non-Catalog Item section) and asks, if the comment should be visible for the supplier or not. Afterwards a third skill sets the user’s answer to another memory field (e.g. {{memory.Item1-Comment-Extern}}) and provides further actions. A memory field determines whether the comment is for item 1, item 2 or an overall comment.


Add a Comment


 

The progress for the header works the same just without asking the user if it should be visible for the supplier. If the user wants to change the quantity, the initial value is reset and two skills fetch a new quantity with the gold entity “number”.

The user also has the possibility to add a second item. This process uses the same skills, with an memory value the bot knows, on which item he is working. If the user wants to finish the PR, a last skill for the web service is triggered.

The skill contains some default values for the PR in case the user did not edit them before:

  • The memory values contain a default header

  • Visibility of the comments to the supplier is set as false if not specified otherwise (e.g. {{memory.Item1-Comment-Extern}})


In the next step the PR is sent to Ariba. For using the Import Requisition web service, also the username, password and the following body are required:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Ariba:Buyer:vsap">
<soapenv:Header>
<urn:Headers>
</urn:Headers>
</soapenv:Header>
<soapenv:Body>
<urn:RequisitionImportPullRequest>
<urn:Requisition_RequisitionImportPull_Item>
<urn:item>
<urn:DefaultLineItem>
<urn:NeedBy>2020-10-15T09:03:44Z</urn:NeedBy>
</urn:DefaultLineItem>
<urn:ImportedHeaderCommentStaging>{{memory.Header-Comment}}</urn:ImportedHeaderCommentStaging>
<urn:ImportedHeaderExternalCommentStaging>{{memory.Header-Comment-Extern}}</urn:ImportedHeaderExternalCommentStaging>
<urn:LineItems>
<urn:item>
<urn:Description>
<urn:SupplierPartNumber>{{memory.Item1-SupplierPartId.raw}}</urn:SupplierPartNumber>
</urn:Description>
<urn:ImportedDeliverToStaging>YOUR USER NAME</urn:ImportedDeliverToStaging>
<urn:ImportedLineCommentStaging>{{memory.Item1-Comment}}</urn:ImportedLineCommentStaging>
<urn:ImportedLineExternalCommentStaging>{{memory.Item1-Comment-Extern}}</urn:ImportedLineExternalCommentStaging>
<urn:NumberInCollection>1</urn:NumberInCollection>
<urn:Quantity>{{memory.Item1-Quantity.scalar}}</urn:Quantity>
<urn:Supplier>
<urn:UniqueName>0001000052</urn:UniqueName>
</urn:Supplier>
</urn:item>
</urn:LineItems>
<urn:Name>{{memory.Header}}</urn:Name>
<urn:Preparer>
<urn:PasswordAdapter>PasswordAdapter1</urn:PasswordAdapter>
<urn:UniqueName>YOUR USER NAME</urn:UniqueName>
</urn:Preparer>
<urn:Requester>
<urn:PasswordAdapter>PasswordAdapter1</urn:PasswordAdapter>
<urn:UniqueName>YOUR USER NAME</urn:UniqueName>
</urn:Requester>
<urn:UniqueName>Caberra 0001</urn:UniqueName>
</urn:item>
</urn:Requisition_RequisitionImportPull_Item>
</urn:RequisitionImportPullRequest>
</soapenv:Body>
</soapenv:Envelope>

 

Unfortunately, the response of the web service is in an XML format, which needs to be converted into JSON. In this case, another API was used. To convert the response, it is send to the SAP Cloud Platform Integration, where a little artifact converts the XML to JSON. Of course you can convert it with any other program aswell.


Raw and Formatted Web Service Response


 

Now the user receives the PR number.

Furthermore, the bot receives the link to the created PR, via the Document Approval API, and provides it to the user.



PR Confirmation


 

Purchase Requisition of a Non-Catalog Item


In case the user wants to place a free-text PR, the user is asked which item he wants to order.


Ask for a Free-Text PR


 

A second “helper” skill, then saves the entire response in memory, analogously to this tutorial.

Two further skills ask for the number of units and the approximate price of the item to be ordered.


Item Quantity Requirements (Price Requirements works analogously)


 

In the last skill, the chatbot connects to a Microsoft Azure Machine Learning Endpoint, submits the free-text PR, which is stored in memory and after a few seconds receive the response which is the predicted material group associated with the free-text PR. Setting up the Machine Learning model is beyond the scope of this tutorial, but you may want to set up a free trial account at Microsoft Azure (or the ML provider of your liking) and build a simple text classification model – which can often be derived from tutorials the provider publishes.


Azure API Authorization


 


Azure API Body


 

The response is saved as a JSON, which then is accessed in the following: The material group together with the other collected information is then submitted to Ariba via web service analogously to the catalog-item skill.

 

Approve Purchase Requisitions


Another feature of the bot is to present the user with pending approvals assigned to him. The user only needs to type in his Ariba username, which then is saved into memory via a regex entity.

In the next step the user receives all his pending approvals as a list. The API used is the Document Approval API, with the username being part of the URL. The list the user then receives, contains a link to the PR in Ariba. In Ariba the user can deny or approve the requests. With this API it is also easy to implement the whole approving process in the SAP CAI.



Pending approvals displayed in MS Teams


 

Conclusion


This blog post should help you to connect SAP Ariba and MS Teams with your bot. The user can fulfil tasks in SAP without signing in.

Since it would be very extensive to describe each step in detail, feel free to ask any questions.

Thanks for reading, hopefully your enjoyed it!
19 Comments
JuanjoGersol
Explorer
Congratulations! Nice work!
lukas_schoeneberger70
Participant
Thanks Juan!
mike_glez
Discoverer
Good work!
juandern
Discoverer
Really interesting, congrats Lukas.
bkron
Explorer
0 Kudos
Very nice! Thanks a lot.

May I ask you a bit more in detail about how you search items in Ariba via Catalog Content API? A colleague of mine tried the same but gave up because he has not found a proper way for it. We of course handling a lot of catalogs and he mentioned we need to search catalgo by catalog by catalog. Due to the fact that we have a rate limit for this API is was not applicable for us. But maybe you found a smoother way and we could reopen this topic internally.
pablo_ruiznavas
Explorer
Superb post, highly detailed, congrats.
lukas_schoeneberger70
Participant
0 Kudos
Thank you Mike!
lukas_schoeneberger70
Participant
0 Kudos
Thank you Juan! 🙂
lukas_schoeneberger70
Participant
0 Kudos
Hi Björn, thanks for your feedback.

Unfortunately I had the same problem, at the moment the bot is only requesting one catalog from one supplier.
lukas_schoeneberger70
Participant
0 Kudos
Thanks Pablo!
former_member548064
Discoverer
Great blog and a very good idea. Hope to try it out myself soon 🙂
bkron
Explorer
OK. Thanks. For us it means we need to wait until Ariba provides better ways to search for items. But never the less this should be the future. Again thanks for sharing this with us.
roy_pappachan2
Participant
Hi Lukas Schöneberger,

Very nice. Great work.

Thanks,

Roy
ivande
Explorer
Hello Lukas,

 

Good job!


Kind regards
Ivan
thomas_herbst2
Discoverer

Great to see how easy integration could be!

kdrescher
Discoverer
Amazing job!
adi_zitawi
Explorer
Great tutorial, thanks for sharing the knowledge, and good luck on the challenge! 💪
0 Kudos
Well done, Lukas! Is there an API available also for creating sourcing requests in Ariba? Thanks in advance.
lukas_schoeneberger70
Participant
0 Kudos
Thanks Fabian! Unfortunately, I'm not that deep in Sourcing. The web service was listed in the integration manager in Ariba, maybe you can find a suitable API there.
Labels in this area