Blog Post

Running SAP Applications on the Microsoft Platform
10 MIN READ

SAP & Teams Integration with Copilot Studio and Generative AI

mimergel's avatar
mimergel
Icon for Microsoft rankMicrosoft
Aug 12, 2024

SAP & Teams Integration with Copilot Studio and Generative AI

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.

 

Example: Product Specification Updates

  • Scenario: Product Managers at Contoso need to review and update product information in their SAP system on a regular basis.
  • Solution: With the SAP and Teams integration provided by Copilot Studio, the product manager at Contoso can easily get the current product information from SAP and update specifications conveniently in an adaptive card.  

By integrating SAP with Microsoft Teams using Copilot Studio and Generative AI, you 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 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.

 

 

 

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: https://learn.microsoft.com/en-us/power-apps/maker/signup-for-powerapps

 

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”:

 

And enter the following details:

 

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

 

 

3.2.        Setup Flow + Connector

In the Actions Tab chose the option to "Create a new flow" at the bottom:

 

Rename the flow to "List SAP products of a category":

 

Add a text Input and Output variable:

 

 

Add an SAP OData action. Choose Query OData entities:

 

 

 

Configure the connection:

 

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

 

Enter the OData Entity “Product Set”:

 

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

 

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

 

Add this expression:

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

 

 

Adjust the output variable to return the found products:

 

In the output add a Power FX expression:

body('Query_OData_entities')

or

string(body('Query_OData_entities'))

 

Finally, the action should look like this:

 

3.3.        Test the flow

Choose Manually and enter the category “Keyboards”:

 

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

 

3.4.        Connect the Copilot with the Flow.

Go back to the copilot studio and refresh the page to see the newly created flow:

 

Chose the previously created flow:

 

Next:

 

 

Edit the Input:

 

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:

 

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

 

Now you should get the response in the chat window:

 

3.6.        Add the Copilot to Teams

Publish the Copilot first:

 

 

Then connect to Teams in the Channels Tab:

 

 

 

Open the Copilot in Teams

 

 

Finally test the Copilot in MS Teams

 

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

 

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

 

 

Open the Topic Details and add the Description

 

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

Create the Input variable

 

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.

 

 

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

 

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

 

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:

 

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 before that gets the products for a specific category and make a copy

 

 

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

 

 

Change the Filter in the new Flow

 

The new filter must be changed to filter on ProductID:

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

 

Then update the action and save the flow.

 

Note: You might wonder why we do not use the "Read Odata Entity". The reason is that in case the ProductID is wrong the Read Entity will through an error whereas the Query simple returns "[]" which makes handling of this situation much easier. 

 

4.3.        Call the Flow from the Topic

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

 

As Input provide the ProductID variable:

 

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:

 

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.

 

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.

 

Select the Output from the Flow as Input.

 

As data type pick “From sample data”

 

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

 

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

 

Enter the sample data to create the schema

 

 

 

Save the result into a new variable called Product.

 

 

4.6.        Adaptive Card with SAP Data

Create a Send message node

 

Send the message as adaptive card

 

 

Enter the following draft adaptive card in JSON format to start with:

https://techcommunity.microsoft.com/gxcuf89792/attachments/gxcuf89792/SAPApplications/1042.22/1/sap_product_adaptive_card_draft.docx 

 

The card will look like this. The Product ID is not yet shown. 

 

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

 

This will change the format slightly removing all the double quotes of the variable names. E.g. "body" becomes body, "type" becomes type, etc. 

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:

 

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/gxcuf89792/attachments/gxcuf89792/SAPApplications/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:

 

Some fields are text inputs and others are just text. This decision is made based on what the user should later be able to change and what not. 

 

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

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.

 

 

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.

 

 

Enter the variable types into the schema binding:

kind: Record

properties:

  action: String

  actionSubmitId: String

  currencyCode: String

  description: String

  price: Number

  productName: String

 

 

Confirm this, save the topic and test again

 

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.

 

Refresh the page and “Turn on” the flow.

 

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

Set the ProductID Input as shown:

 

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

 

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

 

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

 

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

 

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:

 

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

 

Fill in the variables in the respective input fields.

 

 

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

 

Save and test in the copilot test pane.

 

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.

 

Now you can get info about all products in SAP of a category:

 

 

And update SAP product specifications conveniently in an adaptive card: 

 

 

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.

 

Updated Aug 14, 2024
Version 2.0
No CommentsBe the first to comment