When closing an Opportunity in Microsoft Dynamics 365, you may need to customize the Opportunity Close dialog and ensure that the Actual Revenue field is correctly populated. By default, the Actual Revenue might be set to 0 due to out-of-the-box (OOB) processes. This guide will show you how to enable customization for the Opportunity Close form and use JavaScript to auto-populate the Actual Revenue field.
Step 1: Enable Custom Fields on the Opportunity Close Form
By default, Dynamics 365 does not allow additional customizations on the Opportunity Close dialog. To enable it:
- Navigate to Advanced Settings in Dynamics 365.
- Go to Settings > Administration > System Settings.
- Click on the Sales tab.
- Locate the Customize Close Opportunity Form setting.
- Select Yes to enable custom fields on the closing form.
- Click OK to save the changes.
Step 2: Add the Actual Revenue Field to the Opportunity Close Form
Once the customization is enabled, follow these steps:
- Navigate to Power Apps > Solutions.
- Open the Opportunity Close entity.
- Edit the Opportunity Close Form and add the Actual Revenue (actualrevenue) field.
- Save and publish the changes.
Step 3: Use JavaScript to Auto-Populate Actual Revenue
Even after enabling custom fields, the Actual Revenue might still be overridden by OOB processes. To ensure it reflects the actual value from the parent Opportunity, use the following JavaScript:
JavaScript Code
How It Works
- The script retrieves the Actual Value from the parent Opportunity.
- A 500ms delay ensures that the OOB process does not reset the field.
- The retrieved value is then set in the Actual Revenue field.
Step 4: Deploy the JavaScript in Dynamics 365
- Navigate to Power Apps > Solutions.
- Open your solution and go to Web Resources.
- Upload the JavaScript file (e.g.,
hx_/opportunityclose/script/opportunityclose.js
). - Open the Opportunity Close Form.
- Add the onLoad_QuickCreateForm function to the Form OnLoad event.
- Save and publish.
Step 5: Test the Customization
- Create an Opportunity and set an Actual Value.
- Close the Opportunity as Won/Lost.
- Check if the Actual Revenue field is populated correctly.
Conclusion
By following these steps, you can successfully customize the Opportunity Close dialog and auto-populate the Actual Revenue field using JavaScript while bypassing OOB restrictions.
No comments:
Post a Comment