Table of Contents
- Introduction
- User Process Flow
- Create the Dataverse Table
- Creating the Copilot in Copilot Studio
- Enable Generative Selection of Topics
- Create Topics
- Adding Invoice Details Using Adaptive Card
- Fetch Previous Month Invoice Data
- Serialize and Analyze Invoice Data Using AI Prompt
- Display Results
- Conclusion
Introduction
Keeping invoices accurate is crucial to avoid financial mistakes. This blog will show you how to build an Invoice Anomaly Detection system using Copilot Studio. You’ll learn how to input invoice details using an Adaptive Card and compare them with previous month’s data stored in Dataverse. The system will automatically check for any irregularities using AI prompt actions, helping you ensure accuracy and streamline your invoice process.
User Process Flow
- User Inputs Invoice Details:
- The user initiates the process by entering the invoice details through an Adaptive Card. These details include the Product Name, Invoice Amount, Month, and Quantity.
- System Fetches Previous Month Data:
- Upon receiving the current month’s invoice details, the system automatically fetches the previous month’s data from the Dataverse table using the configured connector.
- Data Serialization & Anomaly Detection:
- The system serializes both the current and previous month’s invoice data into a textual format, making it suitable for AI processing.The serialized data is passed to an AI Prompt action, which analyzes the current invoice against the previous month’s data to detect any anomalies.
- Results Display:
- The AI-generated results, highlighting any detected anomalies, are displayed back to the user in an Adaptive Card format. This allows the user to review and take appropriate action based on the insights provided by the system.
Create the Dataverse Table
We will be storing the invoice details in a Dataverse table, which will contain the previous month’s invoices that we’ll be using for spotting any irregularities. It will contain the Product name, Invoice Amount, Month, and Quantity as the columns.
Creating the Copilot in Copilot Studio
-
Head over to Copilot Studio and click on Create.
-
This will provide us the option to create a copilot based on an existing template or create a blank copilot from scratch. Let’s select New Copilot.
-
This will take us to the page where we can describe the copilot functionality and provide any specific instructions to the copilot.
-
Once done, click on Create to provision the copilot.
Enable Generative Selection of Topics
-
The copilot is now created. We can then make the needed configuration changes.
-
Click on Edit and edit the copilot details like name, icon, and description.
-
Click on Settings to enable the Generative selection of topics so that without relying on triggers, the topics will be auto-selected based on user conversation, resulting in a much smoother user experience.
-
To enable the automatic detection of topics from user interaction:
- Click on Generative AI.
- Select Generative (preview).
- Click on Save to update the settings.
- Click on the Close icon to go back to the home page of this custom copilot.
Create Topics
-
Now let’s go ahead and create the topics that will automatically redirect the conversation flow to appropriate topics based on the question the user posts.
-
Click on Topics from the navigation menu.
-
To add the topic, we can either go with the option to create a blank topic or use Copilot to create the topic with an initial set of prepopulated conversation nodes based on the topic description that we provide.
-
Let’s click on Add a Topic and select Create from description with Copilot.
-
Let’s provide the below topic description details in the pop-up that opened when we clicked the Add Topic button previously.
-
Then, click on Create, which will provision the topic skeleton based on the provided description.
Adding Invoice Details Using Adaptive Card
-
Thus we have the basic topic created with an automatic trigger.
-
We can now add more conversation nodes. Let’s add an adaptive card so that the user can add the invoice details as input.
-
We will add the below JSON schema for the adaptive card in the Node properties.
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.4",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"url": "https://adaptivecardsbot.blob.core.windows.net/imagestore/InvoiceProcess.png",
"size": "Small",
"style": "Person"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Invoice Entry Form",
"weight": "Bolder",
"size": "Large",
"wrap": true
}
]
}
]
},
{
"type": "TextBlock",
"text": "Please fill in the details below to submit your invoice.",
"wrap": true,
"weight": "Bolder",
"color": "Good",
"spacing": "Medium"
},
{
"type": "TextBlock",
"text": "Invoice Month",
"weight": "Bolder",
"wrap": true,
"spacing": "Small"
},
{
"type": "Input.Text",
"id": "invoiceMonth",
"placeholder": "Enter Invoice Month (e.g., January)"
},
{
"type": "TextBlock",
"text": "Product Name",
"weight": "Bolder",
"wrap": true,
"spacing": "Small"
},
{
"type": "Input.Text",
"id": "productName",
"placeholder": "Enter Product Name"
},
{
"type": "TextBlock",
"text": "Quantity",
"weight": "Bolder",
"wrap": true,
"spacing": "Small"
},
{
"type": "Input.Number",
"id": "quantity",
"placeholder": "Enter Quantity"
},
{
"type": "TextBlock",
"text": "Invoice Total",
"weight": "Bolder",
"wrap": true,
"spacing": "Small"
},
{
"type": "Input.Number",
"id": "invoiceTotal",
"placeholder": "Enter Invoice Total"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit"
}
],
"style": "default",
"backgroundImage": {
"url": "https://adaptivecardsbot.blob.core.windows.net/imagestore/background.jpg"
}
}
![Adaptive Card](\images\17_CopilotInvoiceAnalyzer\9.png)
- The user-entered values in the adaptive card will be available for use within the Copilot as output variables of the adaptive card.
Fetch Previous Month Invoice Data
-
Now let’s add a variable so that we can use Power Fx to concatenate the user-input values in the format: ProductName: Month: InvoiceTotal (Quantity kg).
-
For example: Copper Wires: March: 1900 (15 kg)
-
We will add the below expression to the newly added variable (varCurrentMonthInvoiceDetails).
Concat(Topic.varFormattedTable, Product & ": " & Month & ":" & Amount & " (" & Quantity & " kg)", ", ")
![Concatenate Values](\images\17_CopilotInvoiceAnalyzer\10.png)
-
Now let’s add the Dataverse connector action to fetch the previous month invoice details from the Monthly Invoices table so that we can compare the current values against it. To do this:
- Select Call an action.
- From the connector tab, search for Dataverse.
- Select List rows from selected environment.
-
Now let’s configure the connector by:
- Mentioning the Environment and table name.
- Click on Advanced inputs so that we can filter the columns that will be returned.
-
Mention the columns that we would like to fetch. In our case, the logical names for Product Name, Month, Quantity, and Invoice Amount are added to the Select columns field.
-
Note: You can get the logical names for these fields by going to the table and selecting the name by navigating the respective columns as shown below:
-
Finally, let’s add an output variable (varInvoiceTable) so that the Dataverse returned data will be stored in table format in this variable.
-
Since there will be a few system columns as well present in the Dataverse returned data, let’s filter the output to retrieve the below filtered table format and we will store it in a new variable (varFormattedTable).
-
For this, we will be using the below Power Fx expression.
ForAll(
Topic.varInvoiceTable,
{
Product: ThisRecord.crfeb_productname,
Month: ThisRecord.crfeb_month,
Amount: ThisRecord.crfeb_invoiceamount,
Quantity: ThisRecord.crfeb_quantitykg
}
)
![Filtered Table](\images\17_CopilotInvoiceAnalyzer\16.png)
Serialize and Analyze Invoice Data Using AI Prompt
-
Since we cannot pass a table as an input to the AI Prompt action, we will serialize the table into the below textual representation, which can be passed as an input to AI prompt.
-
For this, we will add a new variable (varSerializedInvoiceDetails) and use the below expression to concatenate and serialize the table data.
Concat(Topic.varFormattedTable, Product & ": " & Month & ":" & Amount & " (" & Quantity & " kg)", ", ")
![Serialize Data](\images\17_CopilotInvoiceAnalyzer\17.png)
-
Now let’s add the AI Prompt action to which we will pass the serialized invoice data. For this:
- Select Call an action.
- From the Basic actions tab, select Create a prompt.
-
This will open up the pop-up where we can add the prompt that will be used by the AI action. We will:
- Enter the name for the prompt so that this can be selected and added to the Copilot designer later.
- Create the Current Month Invoice and Previous Month Details variables to which we will pass the respective information from the Copilot.
- In the Prompt section, use the below prompt.
- Add the previously created dynamic variables using the Insert button so that they will be added to the prompt during runtime.
- Click on Save custom prompt, which will make the prompt available in the copilot designer.
-
We will add the recently created prompt by:
- Selecting Call an action.
- From the Basic actions tab, select the Invoice Anomaly Checker prompt.
-
The prompt is now available, let’s configure it by adding the below input variables which we had initialized earlier:
- varSerializedInvoiceDetails: The previous month’s Dataverse returned data.
- varCurrentMonthInvoiceDetails: It contains the current user-input invoice data.
-
We will then store the AI prompt returned record output in the (varPredictionOutput) variable which will be used to display the results back to the user.
Display Results
-
Finally, let’s add a basic card and populate it with the below details. The text Property of the varPredictionOutput record variable will contain the generative AI output, which we will add in the formula section of the Adaptive Card Text field.
-
Thus we have completed the creation of a Smart Invoice Anomaly Analyzer.
Conclusion
In this blog, we have successfully created a smart Invoice Anomaly Detection system using Copilot Studio. This system inputs invoice details through an Adaptive Card, fetches the previous month’s data from Dataverse, and uses AI to analyze and spot any anomalies. This approach ensures accuracy and streamlines the invoice processing workflow, making it an essential tool for businesses to avoid costly financial mistakes.
With this setup, your invoice management will become more reliable and automated, allowing you to focus on more critical tasks.