Wednesday 1 June 2016

How to hide POSTS/ACTIVITIES/NOTES tabs from Social Pane CRM

Microsoft introduce "Social Pane" feature in Dynamic CRM 2013, where from user can create and see social posts.

Sometime we need to hide them as per business requirement.

Example: Let say our client business requirement is to hide "SYSTEM POSTS" and "NOTES" from Contact entity form.

Solution: Copy the below javascript and save it in a notepad file. Save the file with the extension(.js).

function HideSocialPaneItems() {
    var tabs = ["SYSTEM POSTS", "NOTES"];
    for (var tabsid = 0; tabsid < tabs.length; tabsid++) {
        HideTabs(tabs[tabsid]);
    }
}

function HideTabs(socialPaneType) {
    var ctrlElement = document.getElementById("header_notescontrol");
    if (ctrlElement.children != null && ctrlElement.children.length > 0) {
        for (var ele = 0; ele < ctrlElement.children.length; ele++) {
            var ctrl = ctrlElement.children[ele];
            if (ctrl.title == socialPaneType) {
                ctrl.style.display = "none";
                if (ele + 1 < ctrlElement.children.length) { ctrlElement.children[ele + 1].click(); return; } else if (ele - 1 >= 0) {
                    ctrlElement.children[ele - 1].click();
                    return;
                }
            }
        }
    }
}

Now create a javascript web resource in the CRM and call it whatever you like, browse to and select the .js file you just created.Next we need to add this web resource to the contact form, where you want to hide the Social Pane Tabs.
Open the form editor and select “Form Properties” from the top toolbar. On the “Events” tab under Form Libraries click “Add” and find the web resource you just created.
In the “Event Handlers” section select “OnLoad” from the drop down list. Click “Add” and select the library you just created.
In the “function” box you must enter the name you gave the function in the script which in this case is “HideSocialPaneItems” as you can see on line 1 of the script.



Solution: In the result view both tabs not displaying.

Note : It's compatible with Dynamic CRM 2013 and 2015 as well without update 1.
 "Use legacy form rendering" for CRM 2015 update 1 and also for CRM 2016 update 1.
Under Settings -> System Settings -> General tab, select Yes 



Wednesday 11 May 2016

How to hide or show Subgrid depending on field value in Dynamic CRM 2016?

Here is the step by step guide about "How to hide a Subgrid in Dynamic CRM".
I found the discussion regarding the same issue in the Forum. So I started following up to come out with a definite answer.
As Microsoft Dynamics CRM 2016 provides several new capabilities and methods to working with sub grids.
As an example let say we need to hide or show the Contact section from the Account form based on the condition of Depending Field see in the picture below.



First of all we need to find the schema name of the sub grid.
You can do this by opening the form editor and then double clicking on the specific sub-grid.

To hide the sub-grid, you want to make sure to use supported JavaScript.
I would like to hide a subgrid depending on what value a Depending Field is showing.
Copy the below javascript and save it in a notepad file. Save the file with the extension(.js).

function HideSubgrid() {
        var dependingfield = Xrm.Page.getAttribute('dependingfield').getValue();
        if(dependingfield == 1)
       {
               Xrm.Page.ui.controls.get('Contacts').setVisible(true);
       }
       else
       {     
              Xrm.Page.ui.controls.get('Contacts').setVisible(false);
        }
}

Create the web resource and call it whatever you like, browse to and select the .js file you just created.


Next we need to add this web resource to the form you want to hide the Subgrid. Open the form editor and select “Form Properties” from the top toolbar.
On the “Events” tab under Form Libraries click “Add” and find the web resource you just created. In the “Event Handlers” section select “OnLoad” from the drop down list. Click “Add” and select the library you just created, in my example it’s called new_hidesubgrid. In the “function” box you must enter the name you gave the function in the script which in this case is “HideSubgrid” as you can see on line 1 of the script.


Click OK, save and publish all your changes and you will see sub grid based will hide or show on base of condition.