The challenge here is that the Opportunity Close entity is separate from the Opportunity entity, and business rules created on the Opportunity Close entity cannot directly access fields from the related Opportunity. However, you can achieve your goal using JavaScript or Power Automate. Here's how:
Use JavaScript
You can write a JavaScript function to dynamically hide specific fields on the Opportunity Close form based on the Opportunity Type selected in the related Opportunity.
Steps:
1. Add JavaScript Library to the Opportunity Close Form
Go to the Opportunity Close form in Dynamics 365.
Add a JavaScript web resource to the form.
2. Write JavaScript Code Use the following script to fetch the Opportunity Type from the related Opportunity and hide fields accordingly:
function onFormLoad(executionContext) {
var formContext = executionContext.getFormContext();
var opportunityId = formContext.getAttribute("opportunityid").getValue();
if (opportunityId) {
// Get the Opportunity ID
var opportunityGuid = opportunityId[0].id.replace("{", "").replace("}", "");
// Call the Web API to retrieve the Opportunity Type
Xrm.WebApi.retrieveRecord("opportunity", opportunityGuid, "?$select=opportunitytype").then(
function (result) {
var opportunityType = result.opportunitytype; // Replace with your field's logical name
// Example: Hide a field based on Opportunity Type
if (opportunityType === 123456) { // Replace 123456 with the option set value
formContext.getControl("field_to_hide").setVisible(false);
} else {
formContext.getControl("field_to_hide").setVisible(true);
}
},
function (error) {
console.error("Error retrieving Opportunity: " + error.message);
}
);
}
}
3. Bind the Script to the Form Load Event
In the Opportunity Close form editor, bind the function onFormLoad to the form’s OnLoad event.
4. Publish the Customizations
Save and publish your changes.