How to Build AI-Generated Charts and PDFs Inside Dynamics 365 CRM Forms (2026 Guide)
Introduction: The Hidden Productivity Gap Inside Your CRM
Here is something that almost every sales team using Dynamics 365 experiences but rarely talks about openly the constant context-switching.
A sales manager opens an Account record to review the pipeline, but the pipeline data lives in Power BI. So they switch tabs. Then they need a proposal for a follow-up opportunity, but that gets built in Word. So they switch again. By the time they come back to the actual CRM record, they have lost minutes sometimes hours per day, just hopping between tools that should have been working together in the first place.
This is not a complaint about Dynamics 365. It is a structural challenge that every CRM faces when reporting and document creation live outside the core record experience. And until recently, there was no elegant way around it.
That is exactly what has changed with the Code Interpreter PCF control a Power Apps Component Framework solution that lets you generate live, AI-powered charts and professional PDFs directly inside your Dynamics 365 forms. No navigation away from the record. No static templates. Just intelligent, context-aware content rendered on the fly.
In this blog, we break down how this works, how to build it, and why it matters whether you are a developer exploring it yourself or an organization working with a Dynamics 365 CRM Development Service to modernize your entire CRM setup.
What Is the Code Interpreter PCF Control?
Before diving into the technical build, it helps to understand what “Code Interpreter” actually means in the Power Platform context because the term gets used loosely and can mean different things depending on where you encounter it.
In Dynamics 365 and the Power Platform ecosystem, Code Interpreter is a capability that can be enabled on AI prompts created through AI Hub or Copilot Studio. When switched on, it allows the prompt to dynamically generate and execute Python code on the server side. Depending on what that Python code produces, the output can be either an HTML page (like an interactive chart) or a downloadable file (like a PDF proposal).
The PCF control is essentially the front-end layer. It sits on a Model-Driven App form, calls the Dataverse Predict API against a configured prompt, and renders whatever the AI returns whether that is an interactive HTML chart with hover effects or a fully formatted PDF document with a download button.
The key architectural principle here is clean separation of concerns: the PCF control handles rendering, and the prompt handles intelligence. You do not need to touch the PCF code at all to switch between generating charts and generating documents. The same control adapts based on what the prompt returns. Swap the Model ID, change the prompt, get entirely different output.
One thing that genuinely surprised us when first working with this setup you can deploy the PCF control once across your entire Dynamics 365 environment and use it across completely unrelated forms and scenarios, just by pointing it at a different prompt. That kind of reusability is rare in custom development and makes the upfront investment go much further than you might expect.
The Two Use Cases That Prove This Works
The team at Vaden Consultancy validated this approach across two concrete real-world scenarios. Both used the same deployed PCF control. The only difference was which AI prompt and therefore which Model GUID was wired up on each form.
Use Case 1: Interactive Pipeline Chart on the Account Form
The problem: A sales manager opening an Account record in Dynamics 365 typically has to leave that record and open a dashboard or Power BI to see the opportunity pipeline breakdown for that specific account. That context switch breaks the flow of reviewing account details.
The solution: A Code Interpreter prompt configured to fetch all Opportunity records related to the Account, group them by sales stage, calculate total estimated revenue and average close probability for each stage, and return a complete, self-contained HTML page with an interactive bar chart.
When a user opens the Account record, the PCF control fires the prompt, passes the Account record ID, and renders the chart inline with hover tooltips, stage-level filters, smooth animations, and a modern color palette. No navigating away. No static screenshot. A live, interactive visual sitting right on the form.
The chart is injected into an iframe using the srcdoc attribute, which means all the JavaScript interactivity works natively. Hover effects, tooltip positioning, animated transitions everything runs inside the sandboxed iframe without any additional configuration.
Use Case 2: AI-Generated Sales Proposal PDF on the Opportunity Form
The problem: Creating a sales proposal typically means leaving the Opportunity record, opening a Word template, manually pulling in revenue numbers, close dates, and account details, and formatting everything before sending. That is a process that pulls a rep completely out of the CRM for 20–30 minutes at a time.
The solution: A second Code Interpreter prompt configured to fetch Opportunity details name, estimated value, close probability, expected close date along with the related Account’s name and contact information, then generate a professional PDF proposal with an executive summary, deal details table, AI-generated solution recommendations, investment summary with discount calculation, and next steps based on the current sales stage.
When a sales rep opens the Opportunity, the PDF renders as an embedded preview inside the form with a download button alongside it. The whole thing is context-aware it only ever pulls data from the record currently open.
Prerequisites: What You Need Before You Build
Getting this working in your Dynamics 365 environment requires a few things in place. Check all of these before writing a single line of configuration skipping one will cost you more time later than checking now.
Code Interpreter enabled at the environment level. This is the most commonly missed step. Navigate to Power Platform Admin Center → Copilot → Settings and turn on Code generation and execution in Copilot Studio. This cannot be done at the app level — it is an environment-wide toggle, and it must be on before any prompt you create can use the capability.
AI Builder capacity. Every call to the Predict API consumes AI Builder credits. For a high-traffic organization, this adds up faster than most people anticipate. Audit your expected usage patterns and monitor consumption in the Power Platform Admin Center before rolling this out broadly. Running into a 403 EntitlementNotAvailable error in production is not a pleasant experience.
Node.js and PAC CLI. You will need both to build and deploy the PCF control. Run pac auth create to connect your CLI to the target environment before starting the deployment steps.
Dataverse connector access for your prompts. The prompts in these scenarios query the Opportunity and Account tables. The Dataverse connector must be explicitly added in the prompt configuration — it is not connected automatically, and prompts without it will silently fail to retrieve any CRM data.
Building the Pipeline Chart: Step by Step
Step 1 — Create the Prompt in AI Hub
What this step accomplishes: You are building the “brain” — the AI prompt that knows how to fetch your CRM data and turn it into an interactive chart.
Go to make.powerapps.com → your environment → AI Hub → Prompts → Create a custom prompt. Name it something clear like “Generate Opportunity Chart” and enable Code Interpreter in the prompt settings.
Add Dataverse connectors for both the Opportunity and Account tables. Navigate to the input section, select Dataverse as the knowledge source, choose the relevant table, and select a field to establish the connection. Do this for both tables before writing the prompt body.
The prompt itself tells the AI exactly what to do: fetch all Opportunities related to the Account ID passed in, group them by sales stage, calculate key metrics for each stage, and return a complete self-contained HTML page with an interactive bar chart. Critically all JavaScript and CSS must be inline. No external CDN references. The output gets injected into an iframe via srcdoc, so any external script references simply will not load.
The reason to force inline HTML rather than a static image matters more than it might seem: an HTML response retains full interactivity. A PNG image does not. Hover effects, filter toggles, animated transitions all of that disappears the moment you switch to image output. Write your prompt to explicitly request an HTML page, not a chart image.
Step 2 — Get the AI Model GUID
What this step accomplishes: You are finding the unique identifier the PCF control needs to know which prompt to call at runtime.
Every prompt created in AI Hub generates a corresponding record in the msdyn_aimodel Dataverse table. The PCF control needs this GUID to know which prompt to call.
Retrieve it by querying the Dataverse API directly in your browser — filter by the prompt name you just created and copy the msdyn_aimodelid value from the JSON response. Keep it somewhere accessible; you will need it in the form configuration step.
Step 3 — Deploy the PCF Control
What this step accomplishes: You are deploying the rendering layer the component that will live on your form and display whatever the AI prompt returns.
Microsoft has published a ready-made sample on GitHub under the PowerApps-Samples repository (CodeInterpreterControl). Clone it, run npm install, build it, and push it to your environment using the PAC CLI. No solution packaging is needed for development and testing.
If you prefer to integrate it into an existing solution rather than using the sample as-is, you can initialize a new PCF project from scratch and wire in the prompt call and rendering logic manually, using the sample as your architectural reference.
Step 4 — Configure It on the Account Form
What this step accomplishes: You are connecting the deployed control to the right form and telling it which AI prompt to use.
Create a placeholder Single Line Text field on the Account table. The PCF control needs a field to anchor to on the form, but it does not actually store data in that field it is purely structural. Open the Account form in the form designer, add the field, go to Properties → Components, and add the Code Interpreter Control.
Set the Model ID to the GUID from Step 2. For Record ID, enter the placeholder 00000000-0000-0000-0000-000000000000 — the control reads the actual record ID at runtime from the Xrm form context automatically. Save, publish, and place the field in a dedicated tab. Naming that tab something like “Pipeline Insights” keeps the form organized and signals to users what they will find there.
Building the PDF Proposal: Step by Step
The PDF scenario follows exactly the same four-step structure. The difference is in the prompt and what output you are requesting.
Create a new prompt “Generate Sales Proposal” with Code Interpreter enabled and Dataverse connectors for both Opportunity and Account tables. This time, the prompt instructs the AI to fetch the Opportunity record and its related Account, then generate a PDF with a styled header, executive summary paragraph, deal details table, AI-generated solution recommendations, investment summary with a discount row, and next steps based on the current sales stage. The critical line in your prompt: return a PDF file, not HTML text. That output instruction is what triggers the file-handling path in the PCF control rather than the HTML rendering path.
When the prompt returns a file instead of text, the control creates a blob URL from the base64-encoded file content and loads it into an iframe for preview. A download button appears automatically alongside the preview. The same file handling logic also supports Word documents and Excel files the control detects the MIME type and routes accordingly, so the same pattern extends to other document types if you need it.
Retrieve the Model GUID for the new prompt, configure the PCF control on the Opportunity form with that GUID, and you are done.
What Actually Surprised Us During Testing
Honestly? Two things caught us off-guard one pleasant, one frustrating.
The pleasant surprise was how much of the chart’s visual quality was controlled entirely through the prompt. We initially assumed the PCF code would need adjustments to get the bar sizing, tooltip positioning, and responsive layout right. It did not. Every visual tweak happened in the prompt text how we described the color palette, the animation behavior, the hover tooltip format. The PCF rendered faithfully whatever the AI returned. That separation made iteration much faster than expected because you are just editing text, not rebuilding a component.
The frustrating one was the Record ID binding. Because the PCF manifest declares the Record ID input as a Single Line Text property, primary key GUIDs do not appear in the form configuration dropdown. There is no obvious way to wire up the current record’s ID directly through the standard field binding UI. The workaround setting a placeholder GUID in the form designer and letting the control read the actual ID from the Xrm form context at runtime works perfectly once you know about it, but it is not documented prominently and cost us real time to figure out. If you hit a wall here, that is almost certainly what is happening.
What Is Happening Under the Hood
The control’s rendering logic follows a clean priority order: if the AI response contains a file (the files array in the response is populated), it renders as a file preview with download button. If there is no file, the text output the HTML chart gets injected into the iframe via srcdoc. Files first, then text. That branching determines everything about how the output appears on the form.
The API call itself goes to the Dataverse bound action endpoint using an HTTP POST, with the Model GUID in the URL and the Record ID passed in the request body as an open dictionary (the OData expando type). The prompt receives the Record ID, queries the relevant Dataverse tables, generates the content server-side, and returns it to the control.
Response time varies depending on data volume and prompt complexity expect somewhere between 5 and 15 seconds for the initial render. This is reasonable for the kind of content being generated, but set expectations with end users upfront and show a clear loading state in the UI. A blank form with no visual feedback for 10 seconds feels broken, even when it is working exactly as intended.
Things to Keep in Mind Before You Roll This Out
Prompt engineering takes real iteration time. Plan for it. Getting the chart to render correctly proper bar sizing, responsive layout, tooltip positioning required multiple rounds of prompt refinement. None of that refinement touched the PCF code. All the tuning happened in the prompt text. Budget this time in your project plan rather than treating it as a quick configuration step.
AI Builder credits are a genuine cost consideration and a good place to involve a Dynamics 365 CRM Consultant early. In a high-traffic organization where many users are opening Account or Opportunity records throughout the day, those Predict API calls accumulate. An experienced consultant can help you model expected credit consumption against your license tier before you commit to a broad rollout, which saves uncomfortable conversations later.
One control, unlimited use cases. The same deployed PCF control supports completely different scenarios just by changing the Model ID and prompt configuration. A case summary on a Case record. A contract draft on a Quote record. An account health report on an Account record. As long as Code Interpreter is enabled and the prompt has access to the right Dataverse tables, the pattern works — and you pay the deployment cost exactly once.
The Record ID workaround is expected, not a bug. Set the Record ID to 00000000-0000-0000-0000-000000000000 in the form designer. The control handles the rest at runtime. This is by design given how the PCF manifest handles GUID-type inputs, not something broken in your setup.
Why This Matters for Customer Engagement Strategy
The context-switching problem is not just a minor inconvenience. The cognitive overhead of switching between a CRM record, a BI dashboard, and a document editor accumulates across an entire sales team over weeks and months. What feels like a small friction point per session becomes a measurable drag on productivity and more importantly on CRM adoption. Users who have to leave the system to do their work eventually stop coming back to it.
When the intelligence comes to the record instead of requiring users to go find it, two things happen. Adoption improves because the system feels genuinely useful inside the workflow people already have. And data quality improves because users stay in the CRM rather than working around it.
This is part of a broader shift in how Microsoft is positioning Dynamics 365 Customer Engagement not just as a system of record, but as a system of intelligence. AI-generated content surfaced directly in context is one of the clearest expressions of that direction.
For organizations working with a Dynamics 365 CRM Implementation Partner in USA, this kind of enhancement is worth raising early in the implementation planning process. The infrastructure it requires AI Builder capacity, Copilot Studio access, Code Interpreter enabled at the environment level is not automatically included in every licensing configuration. Getting those decisions right upfront avoids rework later, and the prompt design work benefits significantly from someone who understands both the technical architecture and the business workflow it is meant to support.
Final Thoughts
The Code Interpreter PCF control represents a meaningful shift in what is possible inside Dynamics 365 forms. Pulling live CRM data, reasoning over it, and rendering context-aware charts or professional documents directly in the record without leaving, without static templates, without manual data entry is a genuine improvement to how sales teams work day to day.
For technical teams, the architecture is clean, reusable, and extensible. For business users, the experience is simply faster and more useful. The intelligence comes to them instead of requiring them to go find it.
The pattern is scenario-agnostic. The infrastructure is available today. The only real question is which problems you want to solve first and how quickly you want to start solving them.
Vaden Consultancy is a Dynamics 365 CRM specialist firm helping businesses across industries unlock the full potential of Microsoft’s customer engagement platform. From CRM strategy and implementation to custom PCF development, AI integration, and ongoing support we delivers solutions built around real business outcomes, not just technical checkboxes.
