An Azure Function that executes FetchXML queries against Microsoft Dataverse and returns results in the JSON format required by Copilot Studio's custom knowledge sources.
This function enables you to use Dataverse data as a custom knowledge source in Copilot Studio by:
- Accepting FetchXML queries via HTTP POST requests
- Executing the queries against your Dataverse environment
- Transforming the results into the specific JSON format that Copilot Studio expects for knowledge sources
This allows your copilots to retrieve and utilize dynamic data from Dataverse tables when answering user questions, leveraging Copilot Studio's OnKnowledgeRequested trigger.
When integrated with Copilot Studio's custom knowledge source feature:
- Copilot Studio determines when knowledge retrieval is needed based on user queries
- The OnKnowledgeRequested trigger activates and calls this Azure Function with a FetchXML query
- The function queries Dataverse using the provided FetchXML
- Results are transformed into the required format with
ContentandContentLocationfields - Copilot Studio uses up to 15 snippets from the results to generate contextually relevant responses
The function returns an array of knowledge base results in the following format:
[
{
"Content": "attribute1:value1, attribute2:value2, ...",
"ContentLocation": "https://your-org.dynamics.com/main.aspx?...&etn=entityname&id=guid"
}
]- Content: A concatenated string of all attribute key-value pairs from the Dataverse entity
- ContentLocation: A deep link to the specific record in your Dataverse environment
The function requires the following configuration settings for connecting to your Dataverse environment. Add these to your appsettings.json or Azure Function application settings:
{
"Dataverse": {
"Url": "https://your-org.crm.dynamics.com/",
"ClientId": "your-azure-ad-app-client-id",
"Secret": "your-azure-ad-app-client-secret"
}
}Required Settings:
- Url: Your Dataverse environment URL
- ClientId: The Application (client) ID from your Azure AD app registration
- Secret: The client secret for your Azure AD app
Note: For local development, use appsettings.local.json (which is git-ignored). For Azure deployment, configure these as Application Settings in the Azure Portal.
When deploying to Azure, you must configure CORS to allow Copilot Studio to call your function:
- Navigate to your Azure Function in the Azure Portal
- Go to Settings > CORS
- Add the following allowed origins:
https://copilotstudio.microsoft.com- Any additional origins where your Copilot Studio instances are hosted
Without proper CORS configuration, Copilot Studio will not be able to call your function.
For a detailed guide on implementing custom knowledge sources in Copilot Studio, see: Custom Knowledge Sources in Copilot Studio
Send a POST request to the function endpoint with a FetchXML query in the request body:
<fetch top="50">
<entity name="account">
<attribute name="name" />
<attribute name="accountnumber" />
</entity>
</fetch>The function will return JSON-formatted results ready for consumption by Copilot Studio.