Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

Hide Custom Activities from Related Activities Based on condition field

Posted on by 140

Hey I want to Hide Custom activity entity from New Activity dropdown based on some field condition 

How could achieve this and is there any scripts or plugins that I could use 

 any code functions or blogs would help 

pastedimage1614893711256v1.png

  • Hide Custom Activities from Related Activities Based on condition field
    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!
     
     
  • Suggested answer
    MehranBre Profile Picture
    MehranBre 730 on at
    RE: Hide Custom Activities from Related Activities Based on condition field

    hi,

    you can use "Custom Rule" of "EnableRule" in RibbonWorkBench.

    add a JS webresource for check your conditions and call this function in Custom Rule of Button.

    Best Regards.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,835 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,526 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans