Enhancing Dynamics 365 HTML Web Resources with Automatically Passed Parameters

 

Enhancing Dynamics 365 HTML Web Resources with Automatically Passed Parameters

In the realm of Microsoft Dynamics 365, HTML web resources serve as a powerful tool to extend the functionality and user interface of the platform. One of the lesser-known but highly useful features is the ability to automatically pass context information, such as the record's unique identifier and object-type code, to these web resources. This capability significantly simplifies the process of creating context-aware custom web pages embedded within Dynamics 365 forms.

Automating Context Passing to Web Resources

Dynamics 365 allows form designers to configure HTML web resources to receive additional context information through URL parameters. Specifically, by selecting the option "Pass record object-type code and unique identifier as parameters" in the web resource properties, Dynamics 365 appends the typename and id parameters to the web resource's URL. This automatically provides the web resource with the object-type code and the unique identifier (GUID) of the current record.



Accessing Passed Parameters in Web Resources

To make use of these automatically passed parameters within your HTML web resource, you can employ JavaScript to parse the URL query string and retrieve these values. Here's a step-by-step guide to accessing and utilizing these parameters in your custom web resource logic:

Step 1: Parse URL Parameters with JavaScript

function getQueryStringParameter(paramToRetrieve)
{
  var params = new URLSearchParams(window.location.search);
return params.get(paramToRetrieve);
}

This utility function uses the URLSearchParams API to parse the query string of the web resource URL and fetch the value of a specified parameter.

Step 2: Retrieve typename and id Parameters

// Retrieve the record's unique identifier (GUID) and object-type code (entity logical name)
var recordId = getQueryStringParameter("id");
var typeName = getQueryStringParameter("typename");

The typename parameter in Dynamics 365 refers to the logical name of the entity associated with the current record

With the getQueryStringParameter function, you can easily extract the typename and id values from the URL, providing your web resource with the context of the Dynamics 365 record it is associated with.

Step 3: Utilize Context Information in Your Web Resource

Having access to the record's unique identifier and object-type code enables your web resource to perform a variety of context-specific operations, such as:

  • Fetching additional data from Dynamics 365 using the Web API.
  • Displaying customized content based on the record type or specific record data.
  • Interacting with other components of the Dynamics 365 form based on the record context.

Real-World Applications

Consider a scenario where you need to display related records or custom visualizations within a Dynamics 365 form. By accessing the id and typename parameters, your HTML web resource can dynamically query related information and tailor the displayed content to the current record, enhancing the user experience and providing valuable insights directly within the form.

Conclusion

Automatically passing context parameters to HTML web resources opens up a wealth of possibilities for customizing and extending Dynamics 365. By leveraging this feature, developers can create more interactive, informative, and user-friendly applications, further unlocking the potential of Dynamics 365 as a comprehensive business management platform.


No comments:

Post a Comment