Power Apps is entering a new era where forms don’t just collect data, they understand it.
With the new Agent APIs in preview, you can bring generative AI directly into your model-driven apps using Copilot Studio. One of the most powerful tools is Xrm.Copilot.executePrompt, which lets you pass dynamic prompts and record context to Copilot and receive intelligent responses right inside the app, no chat window required.
In this post, we’ll walk through how to use it in a real-world field service scenario to generate a technician-ready summary of a work order. We’ll also introduce Xrm.Copilot.executeEvent for more structured scenarios.
What is Xrm.Copilot.executePrompt
This API lets you:
- Send a custom prompt (like: “summarize this work order for the technician”)
- Reference a predefined topic in the interactive agent in the model driven application.
Copilot responds with a structured answer. Summarizing, reasoning, or generating content based on the data in your form.
You’re not triggering a topic or chat. This is AI embedded in your UI.
What you need to use it
To use Xrm.Copilot.executePrompt() or Xrm.Copilot.executeEvent() in your model-driven app, you must configure an Interactive Agent using the following steps:
- In the App Designer, open the Agents pane
- Expand In your app > AI capabilities
- On Interactive agent, select the
...menu and choose Configure - Click Configure in Copilot Studio to create the agent 📌 A new browser tab will open. Make sure pop-ups are enabled.
- In Copilot Studio, add topics, knowledge, or data sources if needed
- Save and publish the agent
- Return to the App Designer tab and click Refresh in the pane header
- Confirm the agent now appears under Interactive Agent
- Save and publish your app

📚 Official docs: Creating an interactive agent
This step is required. If the app isn’t linked to an agent,
executePromptandexecuteEventwill return nothing.
Example: Summarize a Work Order for the Technician
Let’s say your technicians use Dynamics 365 Field Service and want to quickly understand a work order without manually scanning multiple fields.
We’ll create a button that calls Xrm.Copilot.executePrompt to generate a short summary — using current form data and context.
🔧 JavaScript Example
function summarizeWorkOrder(executionContext) {
try {
const formContext = executionContext.getFormContext();
const customer = formContext.getAttribute("msdyn_serviceaccount")?.getValue()?.[0]?.name || "Unknown";
const location = formContext.getAttribute("msdyn_addressname")?.getValue() || "No location specified";
const scheduled = formContext.getAttribute("msdyn_scheduledstart")?.getValue() || "Not scheduled";
const task = formContext.getAttribute("msdyn_workordersummary")?.getValue() || "No task info";
const notes = formContext.getAttribute("msdyn_instructions")?.getValue() || "No instructions provided";
const promptText = `You are a field service assistant helping a technician prepare for a work order.
Customer: ${customer}
Location: ${location}
Scheduled Time: ${scheduled}
Service Task: ${task}
Instructions: ${notes}
Create a short, professional summary that helps the technician understand the job quickly.`;
const parameters = {
prompt: promptText,
context: {
type: "record",
entityName: "msdyn_workorder",
recordId: formContext.data.entity.getId()
}
};
Xrm.Copilot.executePrompt(parameters)
.then(result => {
if (result && result.text) {
Xrm.Navigation.openAlertDialog({
title: "🔧 Work Order Summary",
text: result.text
});
} else {
Xrm.Navigation.openAlertDialog({
title: "No Summary Available",
text: "Copilot didn’t return any result. Try again later."
});
}
})
.catch(error => {
console.error("Copilot API error:", error.message);
Xrm.Navigation.openAlertDialog({
title: "Error",
text: "Something went wrong while calling Copilot:\n" + error.message
});
});
} catch (e) {
console.error("Unexpected error:", e.message);
Xrm.Navigation.openAlertDialog({
title: "Script Error",
text: "An unexpected error occurred:\n" + e.message
});
}
}
💬 Example Output
Work Order Summary:
Visit Skellefteå Kraft on July 15 at 09:00. Replace the coolant pump and confirm pressure calibration. Bring a calibrated gauge and check in with security before starting the job.
What about Xrm.Copilot.executeEvent
If you prefer a more structured setup or want to trigger multiple Copilot experiences, you can use Xrm.Copilot.executeEvent. This method lets you define reusable events inside the agent and pass parameters programmatically.
Example
Xrm.Copilot.executeEvent("summarizeWorkOrder", {
customer: "Skellefteå Kraft",
location: "Main site",
task: "Replace coolant pump"
});
Use executeEvent when:
- You want named events with consistent input
- You need to support multiple Copilot use cases
- You prefer strict parameter handling over open-ended prompts
Best practices
- Make your prompts clear, structured, and contextual
- Use current form data to personalize the AI output
- Always handle cases where no response is returned
- Save and publish both the agent and the app before testing
Final thoughts
With Xrm.Copilot.executePrompt and executeEvent, model-driven apps can finally offer real-time, contextual AI that helps users make sense of what’s in front of them.
For field technicians, this means less time reading, and more time doing.
For makers, it’s a new way to bring value without adding complexity.
We’ve moved beyond building apps. Now we’re building intelligent experiences.
💬 Want help getting started or testing prompts in your app?
Leave a comment. I’d love to hear what you’re working on.


