SAP & Teams Integration with Copilot Studio and Generative AI

  • Thread starter Thread starter mimergel
  • Start date Start date
M

mimergel

SAP & Teams Integration with Copilot Studio and Generative AI​




Introduction​


In this blog, we provide a detailed guide on leveraging AI to optimize SAP workflows within Microsoft Teams. This solution is particularly advantageous for mobile users or those with limited SAP experience, enabling them to efficiently manage even complex, repetitive SAP tasks.

By integrating SAP with Microsoft Teams using Copilot Studio and Generative AI, we can significantly enhance productivity and streamline workflows. This blog will take you through the entire process of setting up a Copilot to interact with SAP data in Teams. We'll utilize the Power Platform and SAP OData Connector to achieve this integration. By following along you will create and configure a Copilot, test and deploy it within Teams, enable Generative AI, build automation flows, and create adaptive cards for dynamic data representation and even change data in SAP.



1. Overview of the Solution​


The solution consists of three main components: Copilot Studio, Power Automate Flow and SAP OData Connector.

  • Copilot Studio is a web-based tool that allows you to create and manage conversational AI agents, called Copilots, that can interact with users through Microsoft Teams.
  • Power Automate Flow is a is a tool that allows you to automate workflows between your applications.
  • SAP OData Connector is a custom connector that enables you to connect to SAP systems using the OData protocol.

The following diagram illustrates how these components work together to provide a seamless SAP and Teams integration experience.



mimergel_87-1723059655519.png





2. Prerequisites​


Before you start building your Copilot, you need to make sure that you have access to the Power Platform and to an SAP system. You can leverage the licenses and SAP systems that are available in your company, or alternatively you can use a trial license for the Power Platform and a public SAP demo system. The following links will guide you on how to obtain these resources if you don't have them already.



2.1. Power Platform Access​




Trial license: Power Apps 30-day free trial - Power Apps



2.2. SAP System Access​




Request SAP Gateway Demo System ES5 Login: https://developers.sap.com/tutorials/gateway-demo-signup.html



3. Create a Copilot​


Now that you have an overview of the solution and have ensured you meet the prerequisites, it's time to dive into the hands-on process of creating a Copilot. This section will guide you through the detailed steps to set up and configure your Copilot, enabling it to interact with SAP data within Microsoft Teams. You'll learn how to leverage Power Automate Flow and the SAP OData Connector to build a robust automated workflow. By the end of this chapter, you will have a fully functional Copilot that can retrieve information about products from the SAP system.



3.1. Create a Copilot​


Create a Copilot with the name “SAP Product Copilot”:

mimergel_1-1723119355082.png



And enter the following details:

mimergel_1-1723059989346.png



Activate “Generative AI” Feature in the Settings of the Copilot

mimergel_2-1723059989348.png



mimergel_3-1723059989364.png



3.2. Setup Flow + Connector​


Create a new “Instant cloud flow” in Power Automate:

mimergel_4-1723059989372.png



Provide the name and chose “Run a flow from Copilot” as trigger:

mimergel_5-1723059989379.png



Add an input variable to the trigger action:

mimergel_6-1723059989382.png



Add an SAP OData action. Choose Query OData entities:

mimergel_7-1723059989386.png



Configure the connection:

mimergel_8-1723059989390.png



OData Base URI: https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC



Enter the OData Entity “Product Set”:

mimergel_9-1723059989394.png



Presse “Show all” to enter a filter in the advanced parameters:

mimergel_10-1723059989401.png





In $Filter you’ll enter a Power FX expression that will filter on the provided Category.

mimergel_11-1723059989410.png



Add this expression:

concat('Category eq ', '''', triggerBody()['text'], '''')



Add a final action that will return the found products.

mimergel_12-1723059989414.png



Find the required action by searching for Copilot

mimergel_13-1723059989420.png



Add an output variable

mimergel_14-1723059989425.png



In the output add a Power FX expression:

mimergel_15-1723059989428.png

body('Query_OData_entities')



Finally, the action should look like this:

mimergel_16-1723059989432.png



3.3. Test the flow​


Choose Manually and enter the category “Keyboards”:

mimergel_0-1723060904124.png



The successful run will indicate that the flow and the connector work fine.

mimergel_1-1723060206356.png



3.4. Connect the Copilot with the Flow.​


Add an action:

mimergel_2-1723060206367.png





Chose the previously created Flow:

mimergel_3-1723060206370.png





Next:

mimergel_4-1723060206374.png





Edit the Input:

mimergel_5-1723060206378.png



And add the following text into the Description. This ensures Gen AI knows how to set the input for the flow:


Product Category. Only one single category can be chosen as input from this list. It is case-sensitive and must be written exactly like below:

Accessories,

Notebooks,

Laser Printers,

Mice,

Keyboards,

Mousepads,

Scanners,

Speakers,

Headsets,

Software,

PCs,

Smartphones,

Tablets,

Servers,

Projectors,

MP3 Players,

Camcorders



Edit the Description of the action output in the same way:


Products found in SAP of a given category.

Present the result as HTML table including following information: ProductID; Name; Category; Description; Supplier; Price; Currency.



3.5. Test the Copilot in the test pane​


Open the Test pane and give it a try:

mimergel_6-1723060206386.png



For the first test you need to connect with the SAP OData Connector:

mimergel_7-1723060206391.png



Now you should get the response in the chat window:

mimergel_8-1723060206397.png



3.6. Add the Copilot to Teams​


Publish the Copilot first:

mimergel_9-1723060206401.png



mimergel_10-1723060206409.png



Then connect to Teams in the Channels Tab:

mimergel_11-1723060206418.png





mimergel_12-1723060206427.png



Open the Copilot in Teams



mimergel_13-1723060206434.png



Finally test the Copilot in MS Teams

mimergel_14-1723060206440.png



You have successfully built a Copilot that can retrieve up-to-date information of products stored in an SAP system and present it in a table format in Microsoft Teams.



4. Use Adaptive Cards to present SAP information​


Now let’s move on by creating adaptive cards to display SAP data dynamically within Microsoft Teams. In this section you will

  • Create and configure topics.
  • Activate topics using the appropriate trigger phrases.
  • Call flows from within topics.
  • Utilize various entities of the SAP OData Connector.
  • Handle special situations, such as when no product is found.
  • Parse JSON data and assign values to topic variables.
  • Design and implement adaptive cards.
  • Understand the differences between actions and topics.

By mastering these skills, you will enhance the functionality and interactivity of your Copilot, providing users with a more intuitive and efficient way to interact with SAP data.



4.1. Create a Topic “SAP Product Data”​


Create a new topic from blank

mimergel_34-1723061688826.png



In the section “Describe what the topic does” Enter the following:


You can copy/paste this description:

This tool can handle queries like these:

sap product update.

Update SAP product.

Update SAP product data.

Edit product information in SAP.

Edit SAP product data.

Show SAP product details.

Edit SAP product information.

Save the Topic
mimergel_35-1723061688833.png





Open the Topic Details and add the Description

mimergel_36-1723061688840.png



Description: “Show and update information about a product in the SAP system.”

Create the Input variable

mimergel_37-1723061688846.png



Save again.



Add a node that asks for the Product ID.


Question:

Which product do you want to update?

Please provide the Product ID.

Example: HT-1000.


mimergel_38-1723061688852.png



In the Identify field choose “User’s entire response”:

mimergel_39-1723061688865.png



Make sure the response will be saved in the variable ProductID:

mimergel_40-1723061688876.png




Note: With GenAI feature enabled the question might not be asked when the ProductID is already known within the context of the conversation, which is very convenient.



Add a Message that will help us to verify if up to here the topic works as designed:

mimergel_41-1723061688881.png



This message can be removed later when all is working fine.





4.2. Create a Flow to get SAP product details​


Take the flow from Lab1 and make a copy

mimergel_0-1723061966754.png



mimergel_1-1723061966763.png



Refresh the page to see the new flow and then turn the flow on

mimergel_2-1723061966785.png





Change the Filter in the new Flow

mimergel_3-1723061966802.png



The new filter must be changed to filter on ProductID:

concat('ProductID eq ', '''', triggerBody()['text'], '''')



Then update the action and save the flow.



4.3. Call the Flow from the Topic​


Add a node “Call Action” and choose the “List SAP product details” flow:

mimergel_4-1723061966823.png



As Input provide the ProductID variable:

mimergel_5-1723061966835.png



Save again.



4.4. Add error handling when no data is found​


Add some error handling in case we got the ProductID wrong, and nothing was found in SAP:

mimergel_0-1723062118115.png



Steps are:

  • Set a condition where Output is equal to “[]” which means no product was found and an empty JSON string was returned.
  • Send a message to inform the user: “The product with ID “ProductID” was not found.”
  • Add a route via “Topic Management” -> “Got to step” and select the destination step where the topic asks for the Product ID.
mimergel_1-1723062118121.pngmimergel_2-1723062118124.png



Save again.



4.5. “Parse value” the Flow Output​


The flow returns a JSON elopement that contains all product details. These must be parsed and assigned to a Table variable.

mimergel_3-1723062118131.png



Select the Output from the Flow as Input.

mimergel_4-1723062118140.png



As data type pick “From sample data”

mimergel_5-1723062118143.png



Get the sample data from a flow test run with a known Product ID

mimergel_6-1723062118152.png



You can copy/paste the sample data from the successful flow run. Either get it in the output of respond to copilot or take it from the Odata query output

mimergel_7-1723062118158.pngmimergel_8-1723062118161.png



Enter the sample data to create the schema

mimergel_9-1723062118165.png





mimergel_10-1723062118173.png



Save the result into a new variable called Product.

mimergel_11-1723062118185.png





4.6. Adaptive Card with SAP Data​


Create a Send message node

mimergel_0-1723062376157.png



Send the message as adaptive card

mimergel_1-1723062376165.png





Enter the following draft adaptive card JSON to start with:

https://techcommunity.microsoft.com...042.22/1/sap_product_adaptive_card_draft.docx



The card will look like this:

mimergel_2-1723062376170.png



As a next step make the adaptive card dynamically showing the values from the Product Table. For this you must switch to Formula:

mimergel_3-1723062376176.png



This will change the format slightly removing all the double quotes of the variable names.

Edit the last Entry from

"text": "${Topic.ProductID}"

To:

text: Topic.ProductID



Save and test again. Now you have an adaptive card showing dynamically a value returned by the flow:

mimergel_8-1723062777709.png



As a next step add the full code from the link below to show all the SAP information in the adaptive card:

https://techcommunity.microsoft.com...ions/1042.22/2/sap_product_adaptive_card.docx




Note: You can create your own design and adaptive cards JSON code here: https://adaptivecards.io/designer/



Save and run another test:

mimergel_9-1723062866881.png







5. Changing the data within SAP​


To advance the copilot capabilities even further, you can enable changing product information in SAP. Therefore, the following steps must be done:

  • Initiate actions from adaptive cards by using the “Ask with adaptive card” node.
  • Create another flow to update data and use the update entity in the SAP OData connector.
  • Configure more additional variables handling in the topic
  • Update the Copilot to use the “update” flow.



5.1. Add “Ask with adaptive card” Node​





Add a node “Ask with adaptive card”



See also:

Ask with Adaptive Cards - Microsoft Copilot Studio | Microsoft Learn
mimergel_0-1723107523047.png

Take the code from the previously created adaptive card.

Add the action “Submit” at the end of the AC code.

,

actions: [

{

type: "Action.Submit",

title: "Submit Changes",

horizontalAlignment: "Center",

data: {

action: "submitProductChanges"

}

}

]



Save this adaptive card.



Delete the previously created AC as we don’t need it any longer.
mimergel_1-1723107606465.png




When you get the error about missing properties, meaning the Adaptive Card editor did not automatically create the output structure you need to edit the schema manually.

Edit schema on the bottom right.



mimergel_0-1723107765663.png



Enter the variable types into the schema binding:


kind: Record

properties:

action: String

actionSubmitId: String

currencyCode: String

description: String

price: Number

productName: String



mimergel_1-1723107849038.png



Confirm this, save the topic and test again


mimergel_2-1723107867943.png




5.2. Create “Update SAP Product Details” Flow​


The final step is to run another flow that will update the product information in SAP.

Create another flow with the same copy procedure as before.

mimergel_0-1723107961067.png



Refresh the page and “Turn on” the flow.

mimergel_1-1723107961078.png



At second position add an action “SAP OData Connector” with the Entity “Update OData entity”.

Set the ProductID Input as shown:

mimergel_2-1723107961089.png



In the advanced parameters mark those where we want to allow updates. These are Name, Description, Price and CurrencyCode:

mimergel_3-1723107961102.png



Add the additionally required Flow Parameters. (Note: Price is a number):

mimergel_4-1723107961107.png



Update the “Update Odata entity” Actions with the relevant variables in the corresponding fields:

mimergel_5-1723107961111.png



Update the last action in the flow with the success message:

mimergel_6-1723107961114.png



5.3. Update the Copilot Topic to call the update flow​


After the adaptive card node add the node “Call an action” and pick the “Update SAP product detail” flow:

mimergel_0-1723108136158.png



Open the “variable” pane and activate the required variables.

mimergel_1-1723108136173.png



Fill in the variables in the respective input fields.

mimergel_2-1723108136178.png





The last step is to send the message about the successful product information update:

mimergel_3-1723108136181.png



Save and test in the copilot test pane.

mimergel_4-1723108136194.png



When all works fine you can publish again and test the functionality in MS Teams. You’ll need to trigger the Copilot update in MS Teams with the “Start over” trigger phrase.



mimergel_5-1723108136202.png



We hope you enjoyed following along this blog and that you will find it useful for your own SAP projects.



6. Conclusion​


With the steps outlined in this blog, you are now equipped to fully leverage the integration of SAP with Microsoft Teams using Copilot Studio and Generative AI. You can use any available SAP OData service or even create your own, enabling seamless access and management of SAP data within Teams. This integration not only simplifies workflows but also transforms simple, repetitive tasks into significant value-adding activities for users.

You can enable even those users with little or no SAP know-how to complete SAP-specific tasks, thanks to the built-in Generative AI feature that can always help and answer every question. As you explore and implement these capabilities, you'll discover new opportunities to enhance productivity and drive innovation in your SAP related digital workspace.

The future of integrated, AI-powered collaboration is here, and it hopefully starts with your next SAP and Teams integration scenario.

Continue reading...
 
Back
Top