I would like to know if there is a way to enable or disable a DocuTemplate dynamically based on a condition, such as a checkbox in a form.
For example, if a user selects a specific option in the UI, the document template should become available or unavailable accordingly. I am looking for a solution that does not require manually removing or re-adding the template but rather controlling its availability dynamically.
The template is not manually created but is installed through an extension of the DocuTemplateRegistrationBase class and the implementation of the LedgerIJournalExcelTemplate interface.
So far, the only workaround I have found is modifying the DocuTemplate record and setting an invalid value in the TemplateType field to prevent the template from being displayed. However, I am unsure if this is a recommended approach or if there is a more standard way to achieve this.
Is there any best practice or alternative solution for this in D365FO? Any guidance or suggestions would be greatly appreciated.
Hi there! Good morning, evening, or afternoon - depending on where you are :) Hope you are well today!
To dynamically enable or disable a DocuTemplate in Dynamics 365 Finance and Operations (D365FO) based on a condition (e.g., a checkbox in a form), here are some approaches you can consider: 1. Use a Custom Field or Flag
Add a custom field (e.g., IsTemplateEnabled) to the DocuTemplate table.
Update the logic in your extension of the DocuTemplateRegistrationBase class to check this field before making the template available.
Example:
public override boolean isTemplateEnabled()
{
return this.DocuTemplate.IsTemplateEnabled;
}
Dynamically update the IsTemplateEnabled field based on the user's selection in the UI.
2. Modify the Template Availability Logic
Extend the LedgerIJournalExcelTemplate interface or the relevant class to include conditional logic for enabling/disabling the template.
Use a parameter or a global variable to control the availability of the template.
3. Leverage Form Event Handlers
Use form event handlers to dynamically control the visibility or availability of the template in the UI:
Add a checkbox to the form.
Use the OnModified event of the checkbox to trigger logic that updates the template's availability.
4. Avoid Modifying the TemplateType Field
While modifying the TemplateType field to an invalid value can prevent the template from being displayed, it is not a recommended approach as it may lead to unintended side effects or maintenance challenges.
5. Best Practice: Use a Configuration Parameter
Create a configuration parameter in System Administration > Setup > Parameters to control the availability of the template.
Update the logic in your extension to check the value of this parameter before enabling the template.
6. Test the Solution
After implementing the changes, thoroughly test the solution to ensure that the template's availability is dynamically controlled as expected.
This approach ensures that the template's availability is managed dynamically without requiring manual intervention or risky workarounds.
Was this reply helpful?YesNo
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.