Dynamics 365





Saturday, December 14, 2013

CRM 2011 - Auto populate values on lookup value selected - json ODATA

On Lookup up change get Account Entity values get auto populated using ODATA JSON script

function retrieveRecord() {

    var odataSetName = "AccountSet";
    debugger;
    var accountLookup = Xrm.Page.getAttribute("pmax_companyname1").getValue();
    if (accountLookup != null) {
        var AccountID = accountLookup[0].id;
    }
    // Get Server URL

    var serverUrl = Xrm.Page.context.getServerUrl();

    var serverUrl = "http://117.218.28.36/pmax-crm";

    //The OData end-point

    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

    //Asynchronous AJAX function to Retrieve a CRM record using OData
    debugger;
    $.ajax({

        type: "GET",

        contentType: "application/json; charset=utf-8", datatype: "json",

        url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + AccountID + "')",

        beforeSend: function (XMLHttpRequest) {

            //Specifying this header ensures that the results will be returned as JSON.

            XMLHttpRequest.setRequestHeader("Accept", "application/json");

        },

        success: function (data, textStatus, XmlHttpRequest) {

            readRecord(data, textStatus, XmlHttpRequest)

        },

        error: function (XmlHttpRequest, textStatus, errorThrown) {

            alert("Error – " + errorThrown)

        }

    });

}

    function readRecord(data, textStatus, XmlHttpRequest) {

    alert("Record read successfully!!");

    var account = data;

    alert("Name – " + account.d.Telephone1);
    alert("Name – " + account.d.WebSiteURL);

    Xrm.Page.getAttribute("pmax_website").setValue(account.d.WebSiteURL);
    Xrm.Page.getAttribute("pmax_website").setSubmitMode("always");

    Xrm.Page.getAttribute("pmax_businessphone").setValue(account.d.Telephone1);
    Xrm.Page.getAttribute("pmax_businessphone").setSubmitMode("always");
  

    }

Thursday, December 12, 2013

Default the Activities 'Filter on' to 'All' for Account and Contact - CRM 2011


Default the Activities 'Filter on' to 'All' for Account and Contact

 

//default the Activities 'Filter on' to 'All' for Account and Contact 

function filterAllActivities() {
    document.getElementById("navActivities").onclick = function () {
        loadArea("areaActivities"); 
        document.getElementById("areaActivitiesFrame").onload = function () {
            var entityName = Xrm.Page.data.entity.getEntityName();
            var entity = entityName.charAt(0).toUpperCase() + entityName.substr(1);
            var doc = this.contentWindow.document;
            var filterOn = doc.getElementById("crmGrid_" + entity + "_ActivityPointers_datefilter"); 
            filterOn.value = "All";
            filterOn.FireOnChange();
        };
    };