Opening an HTML Web Resource from a Subgrid Button in Dynamics 365 CRM
An Australia-based linen manufacturing and distribution company was using Microsoft Dynamics 365 to manage their sales lifecycle.
Their sales process included:
- Opportunities
- Products stored in the Product entity
- Opportunity Products added through a subgrid
The issue arose when sales representatives needed to add multiple existing products to an Opportunity.
The Real Problem
Out-of-the-box behavior in Dynamics 365 allows users to:
- Click Add Existing Product
- Search for a product
- Select one product
- Save
- Repeat the process again and again
While this works functionally, it becomes inefficient for organizations managing:
- Large product catalogs
- Multiple product variations
- Frequent bulk product additions
This resulted in:
- Increased manual effort
- Operationally inefficient
- Reduced sales productivity
The business requirement was clear:
Users should be able to select multiple existing products and create Opportunity Product records in bulk, from a single interface.
Architectural Decision
Instead of:
- Customizing standard dialogs
- Implementing complex client-side overrides
- Writing heavy synchronous plugins
To address this, we introduced a custom button on the Opportunity Products subgrid. When clicked, it opens an HTML web resource that allows users to select multiple existing products in a single interface. The selected products are then processed through a Custom Action, which handles the bulk creation of Opportunity Product records server-side.
Why Use an HTML Web Resource?
In Microsoft Dataverse, not every customization belongs directly inside the main form.
Sometimes we need:
- A richer UI
- Multi-select capabilities
- Controlled record creation logic
- Better user workflow control
HTML Web Resources allow us to build:
- Custom layouts
- Advanced selection logic
- Grid-style interfaces
- Batch record creation
Without disturbing the standard CRM experience.
The Web Resource
We created an HTML web resource named:
new_BulkAddOpportunityProducts.html
The HTML web resource renders a searchable grid of existing Product records, allowing users to perform multi-selection. The selected product IDs are then passed to a Custom Action, which handles the creation of related Opportunity Product records against the active Opportunity.
Opening the HTML Web Resource from the Subgrid Button
The key technical step was opening the HTML page when the custom ribbon button is clicked.
We used modern navigation APIs.
JavaScript Used on the Ribbon Button
function openBulkProductSelector(executionContext) {
var formContext = executionContext.getFormContext();
var opportunityId = formContext.data.entity.getId();
if (!opportunityId) {
console.log("No Opportunity record found.");
return;
}
var pageInput = {
pageType: "webresource",
webresourceName: "new_BulkAddOpportunityProducts.html",
data: opportunityId.replace("{", "").replace("}", "")
};
var navigationOptions = {
target: 2, // Opens as dialog
width: 900,
height: 600,
position: 1
};
Xrm.Navigation.navigateTo(pageInput, navigationOptions)
.then(function () {
console.log("Web resource opened successfully.");
})
.catch(function (error) {
console.error("Error opening web resource:", error);
});
} How This Works
When the custom button is clicked, the script first retrieves the current Opportunity record ID. This ID is then passed as a parameter to the HTML web resource so that the selected products can be associated with the correct Opportunity. The web resource is opened as a modal dialog using the target: 2 navigation option, ensuring that users can complete the bulk selection process without leaving the form.
Inside the HTML Web Resource
Within the HTML web resource:
- The Opportunity ID is retrieved from query string parameters.
- Users select multiple existing products.
- The selected product IDs are passed to a Custom Action.
- The Custom Action executes server-side logic to create Opportunity Product records.
This design ensures:
- Business logic remains server-side
- Bulk record creation is transactional
- Validation rules are centrally managed
- Security context is respected
All without navigating away from the form.
How This Approach Saved Time
Faster User Workflow
Users select multiple products in one screen.
Clean Architecture
| Concern | Where It Lives |
|---|---|
| Business Data | Dataverse |
| UI Interaction | HTML Web Resource |
| Batch Logic | Custom Action (C# Plugin) |
To encapsulate, with this design the Client was able to:
- Reduced repetitive clicks
- Improved sales efficiency
- Cleaner CRM customization
Opening an HTML Web Resource from a button in Microsoft Dynamics 365 is a powerful extension technique.
It allows organizations to:
- Enhance user experience
- Maintain architectural clarity
- Extend CRM safely and cleanly
We hope you found this blog useful, and if you would like to discuss anything, you can reach out to us at transform@cloudfronts.com