This guide explains how to pass parameters from a Dynamics 365 main form to an HTML web resource by enabling a built-in feature and retrieving the parameters dynamically in your HTML.
Step 1: Enable Parameter Passing in the Web Resource Settings
- Open the Form Editor for the desired entity.
- Add or edit your HTML web resource.
- Under the Advanced section of the web resource configuration:
- Check the option Pass record object-type code and unique identifier as parameters (as shown in the image).
- Save and publish your changes.
This setting automatically passes the following parameters to the web resource:
id
: The unique identifier (GUID) of the current record.typename
: The logical name of the entity associated with the current record.
Step 2: Parse URL Parameters in the HTML Web Resource
Use JavaScript in your HTML web resource to retrieve the passed parameters. The URLSearchParams
API simplifies parsing the query string.
Utility Function to Parse Parameters
This function retrieves the value of any parameter in the query string.
Step 3: Retrieve the id
and typename
Parameters
With the above utility function, extract the id
and typename
parameters dynamically in your HTML.
Example Code:
Step 4: Use the Parameters in the HTML Web Resource
You can utilize the extracted parameters to dynamically display or process data related to the current record.
Example: Displaying Record Details in HTML
Step 5: Test Your Web Resource
- Open any record in Dynamics 365.
- Verify that the web resource correctly displays or uses the
id
andtypename
parameters. - Use browser developer tools to inspect the query string and debug if needed.
By simply enabling the Pass record object-type code and unique identifier as parameters option and implementing URL parameter parsing in your HTML, you can create powerful, dynamic web resources in Dynamics 365.
No comments:
Post a Comment