Hey,
To hide a custom activity entity from the "New Activity" dropdown based on a field condition, you can use JavaScript code and the Xrm object model provided by the Dynamics 365 platform. Here's an example of how you can achieve this:
// Function to check the field condition and hide the custom activity entity
function hideCustomActivityEntity() {
var formContext = Xrm.Page;
// Replace "custom_activity" with the logical name of your custom activity entity
var customActivityEntityName = "custom_activity";
// Replace "field_name" with the name of the field you want to check the condition on
var fieldName = "field_name";
// Replace "condition_value" with the value that should trigger hiding the entity
var conditionValue = "condition_value";
// Retrieve the field value
var fieldValue = formContext.getAttribute(fieldName).getValue();
// Get the "New Activity" dropdown control
var newActivityDropdown = formContext.ui.controls.get("navActivities");
// Check the field condition and hide the custom activity entity if the condition is met
if (fieldValue === conditionValue) {
for (var i = 0; i < newActivityDropdown.getControl().childNodes.length; i++) {
var childNode = newActivityDropdown.getControl().childNodes[i];
if (childNode.getAttribute("name") === customActivityEntityName) {
childNode.style.display = "none";
break;
}
}
}
}
// Register the function to execute on form load and field change events
function registerCustomActivityEntityHide() {
var formContext = Xrm.Page;
// Replace "field_name" with the name of the field you want to trigger the condition check on
var fieldName = "field_name";
// Execute the function on form load
formContext.data.entity.addOnLoad(hideCustomActivityEntity);
// Execute the function whenever the field value changes
formContext.getAttribute(fieldName).addOnChange(hideCustomActivityEntity);
}
// Execute the registration function
registerCustomActivityEntityHide();
You need to place this code in a web resource and add it to the form where you want to hide the custom activity entity. Replace the placeholders with the appropriate values for your custom activity entity, field, and condition.
Once the code is in place, the custom activity entity will be hidden from the "New Activity" dropdown whenever the specified field meets the condition you defined.
Note: This solution assumes you're using the legacy web client in Dynamics 365. If you're using the Unified Interface, you may need to modify the code accordingly.
I hope this helps!