How to Create an HTML Web Resource and Display Attachments in Timeline
How to Create an HTML Web Resource and Display Attachments in Timeline
Dynamics 365 allows developers to extend model-driven applications using HTML Web Resources. These web resources can be used to display custom information, integrate external systems, and enhance the user experience.
A common requirement is displaying timeline attachments such as documents, images, PDFs, and notes inside a custom HTML Web Resource. This approach provides greater flexibility and a more customized interface than the standard timeline control.
What is an HTML Web Resource?
An HTML Web Resource is a custom web page that can be embedded within Dynamics 365 forms, dashboards, and sitemap areas.
- Create custom user interfaces
- Display external data
- Call Dataverse Web APIs
- Extend model-driven apps
- Build reusable components
Create an HTML Web Resource
Create a new HTML file and upload it as a Web Resource.
<html> <head> <title>Timeline Attachments</title> </head> <body> <div id="attachmentContainer"> </div> </body> </html>
Retrieve Timeline Attachments
Use the Dataverse Web API to retrieve Note attachments stored in the Annotation table.
Xrm.WebApi.retrieveMultipleRecords( "annotation", "?$select=filename,filesize,mimetype" )
This returns attachment details associated with timeline records.
Display Attachments in HTML
Loop through the returned records and generate HTML dynamically.
result.entities.forEach(function(item)
{
document
.getElementById(
"attachmentContainer"
)
.innerHTML +=
"<div>" +
item.filename +
"</div>";
});
Add Download Links
Provide users with direct download access for attachments.
<a href="downloadUrl"> Download File </a>Important: Ensure users have appropriate Dataverse permissions to access annotation records and attachment files.
Implementation Steps
- Create an HTML Web Resource.
- Upload it to Dynamics 365.
- Add JavaScript for Web API calls.
- Retrieve annotation records.
- Display attachment information.
- Add the Web Resource to the form.
- Publish customizations.
- Test file access and downloads.
Common Use Cases
- Custom attachment viewers
- Document management dashboards
- Customer file portals
- Timeline enhancements
- Case management solutions
- Project document repositories
Best Practices
- Use asynchronous Web API calls.
- Validate file permissions.
- Implement error handling.
- Optimize large attachment lists.
- Follow responsive design principles.
Key Takeaways
- HTML Web Resources provide flexible UI customization.
- Timeline attachments can be retrieved using Dataverse Web API.
- Custom attachment viewers improve user experience.
- JavaScript enables dynamic file rendering.
- Works seamlessly within Dynamics 365 model-driven apps.