Tuesday, 5 December 2017

Change default view of Related Activities to 'All Activities' instead of 'Open Activity Associated View' (Account)

Set default filter for associated view

Description:

In this example we explain that how to set the Default Associated view to All in Dynamic CRM.or how to set default filter for associated view in Dynamic CRM using JavaScript. Or change default view of related activities to “All Activities” instead of “Open Activity Associated View” in dynamic CRM.or how to set default filter for associated view in dynamic CRM using XRM and JavaScript. Or set default associated view to All in dynamic CRM.

here we create one javascript function and call it in form load of the dynamic crm.
Javascript Function :

function forwardValues() {
        //debugger;
        var oId = Xrm.Page.data.entity.getId();
        if (oId != null) {
            var IFrame = Xrm.Page.ui.controls.get("IFRAME_Associated");
            var Url = IFrame.getSrc();
            if (Url.indexOf("?") != -1)
            // alert(Url.indexOf("?"));
                Url = Url.substr(0, Url.indexOf("?"));
            var param2 = "&oType=1&pagemode=iframe&security=852023&tabSet=Account_ActivityPointers&rof=true&inlineEdit=1";
            var param1 = Url + "?oId=" + oId + param2;
            //alert(param1);
            IFrame.setSrc(param1);

            document.getElementById("IFRAME_Associated").onload = function () {
                //alert("Hello");
                var entityName = Xrm.Page.data.entity.getEntityName();
                //alert("EntityName");
                var entity = entityName.charAt(0).toUpperCase() + entityName.substr(1);
                //alert("Entity");
                var doc = this.contentWindow.document;
                var filterOn = doc.getElementById("crmGrid_" + entity + "_ActivityPointers_datefilter");

                filterOn.value = "All";
                setSelectorView(doc);

                var evt = document.createEvent("HTMLEvents");
                evt.initEvent("change", false, true);
                filterOn.dispatchEvent(evt);


            };
        }
    }
    function setSelectorView(doc) {
        var control = doc.getElementById("crmGrid_Account_ActivityPointers_SavedNewQuerySelector").control;
        var selectionControl = control.get_selectionControl();
        if (!selectionControl) { //selectionControl not there? wait 200ms and check again.
            setTimeout(function () {
                //   console.log("selectionControl is null.");
                setSelectorView(doc);
            }, 200);
            return;
        }
        control.setViewForNewSavedQuerySelector("All Activity", "00000000-0000-0000-00AA-000010001902", 1039);   //   here this is the Id of the All Activity you can change as per your requirement.
        doc.defaultView.handleView(null, selectionControl);
    }




0 comments:

Post a Comment