الأربعاء، 6 سبتمبر 2017

Dynamics 365: How to get Entity Definition for specific entity to use in Web API

To get the Entity Definition for specific entity to use in Web API set the following in URL in browser :
[Organization URI]/api/data/v8.2/EntityDefinitions?$select=DisplayName,EntitySetName&$filter=SchemaName eq 'your_entity_SchemaName'

then use entity set name as Entity Definition as below example:




(Note:Example of SchemaName for entity logical name 'productpricelevel' = 'ProductPriceLevel' )

Ex:https://bbbb.crm4.dynamics.com/api/data/v8.2/EntityDefinitions?$select=DisplayName,EntitySetName&$filter=SchemaName eq 'UoM'

Dynamics 365 / CRM 2016 : Using Web API Operations - Retrieve Single or Multiple Records

In MS CRM 2016, Web API introduced to perform operations on MS CRM using JavaScript. 

      function retrieveSingleRecord (entityDefinitions, recordId) {
        /// <summary>
        /// Retrieving single record using Web API by record ID.
        /// </summary>
        /// <param name="entityDefinitions" type="string">
        /// EntitySetName (ex:for Account entity, the entity set name is accounts)
        /// </param>
        /// <param name="recordId" type="string">
        /// A string represents a guid for record Id.
        /// </param>
        /// <returns type="Object" />

        recordId = recordId.replace(/[\{\}]+/g, '');

        var apiUrl = Xrm.Page.context.getClientUrl() + "/api/data/v8.1/" + entityDefinitions + "(" + recordId + ")";

        var req = GetRequestObject();

        if (req != null) {
            req.open("GET", apiUrl, false);
            req.setRequestHeader("OData-MaxVersion", "4.0");
            req.setRequestHeader("OData-Version", "4.0");
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            req.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
            req.send(null);

            var requestResults = JSON.parse(req.response)

            return requestResults;
        }
        return false;
    }
//**************************************************************************
    function retrieveSingleRecord_WithCallBack (entityDefinitions, recordId, successCallBackFun) {
        /// <summary>
        /// Retrieving single record using Web API by record ID with callback function.
        /// </summary>
        /// <param name="entityDefinitions" type="string">
        /// EntitySetName (ex:for Account entity, the entity set name is accounts)
        /// </param>
        /// <param name="recordId" type="string">
        /// A string represents a guid for record Id.
        /// </param>
        /// <param name="successCallBackFun" type="function">
        /// callback function.
        /// </param>
        /// <returns type="void" />

        recordId = recordId.replace(/[\{\}]+/g, '');

        var apiUrl = Xrm.Page.context.getClientUrl()+ "/api/data/v8.1/" + entityDefinitions + "(" + recordId + ")";

        //Ex:https://vvvvv.crm4.dynamics.com/api/data/v8.2/accounts(A0A00F3A-1166-E711-80E1-3863BB343B78)

        var req = new XMLHttpRequest();
        req.open("GET", apiUrl, true);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");

        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    var result = JSON.parse(this.response);
                    //alert(result["name"]);
                    successCallBackFun(result);
                }
                else {
                    alert(this.statusText);
                }
            }
        };
        req.send();
    }

//**************************************************************************

    function retrieveMultiple (entityDefinitions, filterUrl) {

        /// <summary>
        /// Retrieving multiple records based on specific filter criteria.
        /// </summary>
        /// <param name="entityDefinitions" type="string">
        /// EntitySetName (ex:for Account entity, the entity set name is accounts)
        /// </param>
        /// <param name="filterUrl" type="string">
        /// a string url to specify filter criteria using $filter(ex:$filter=cusomerid eq cusomeridvalue).
        /// </param>
        /// <returns type="Object" />

        var apiUrl = Xrm.Page.context.getClientUrl() + "/api/data/v8.1/" + entityDefinitions + "?" + filterUrl + "&$count=true";

        var req = GetRequestObject();

        if (req != null) {
            req.open("GET", apiUrl, false);
            req.setRequestHeader("OData-MaxVersion", "4.0");
            req.setRequestHeader("OData-Version", "4.0");
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            req.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
            req.send(null);
            var requestResults = JSON.parse(req.response)

            return requestResults;
        }
        return false;
    }

Dynamics 365:How to filter lookup control based on another lookup value using JavaScript

Ex:Display only the contacts that belong to selected account.

//when account lookup value changed
function onAccountChanged() {
    var AccountId = getLookupValue("customerid");
    if (AccountId != null) {

        Xrm.Page.getControl("contactid").removePreSearch(function () {
            addLookupFilter();
        });

        Xrm.Page.getControl("contactid").addPreSearch(function () {
            addLookupFilter();
        });

        Xrm.Page.getAttribute("contactid").setValue(null);
    }

    else {

        Xrm.Page.getControl("contactid").removePreSearch(function () {
            addLookupFilter();
        });

        Xrm.Page.getAttribute("contactid").setValue(null);

    }
}

function addLookupFilter() { 
    var accountId = getLookupValue("customerid"); 

    var fetchXml = "<filter type='and'><condition value='" + accountId + "' attribute='parentcustomerid' uitype='account'  operator='eq' /></filter>";
    Xrm.Page.getControl("alfa_address").addCustomFilter(fetchXml);
}
 //***************************
function getLookupValue(fieldname) {
    var lookupObj = Xrm.Page.getAttribute(fieldname);
    if (lookupObj.getValue() != null)
        return lookupObj.getValue()[0].id;
    else
        return null;
};

الخميس، 13 يوليو 2017

Dynamics 365: Adding Bing Map control to forms of custom entity

Starting from CRM 2013 Microsoft released a really great feature OOB (Out Of the Box) integration with BingMaps. Unfortunately, the list of entities that support BingMaps control is limited to Account, Contact, Lead, Quote, Order, Invoice, Competitor, and System User.So when trying to add Bing Maps to form the icon is grayed out on the insert ribbon for a form - in particular for a custom form.

To Solve this issue follow the below link:

الخميس، 27 أبريل 2017

SharePoint 2013 Preparation tool stuck in configuring Application Server Role, Web Server IIS Role

I'm trying to install the Prerequisites by running the prerequisiteinstaller.exe but I'm stuck in this Application Server Role, Web Server (IIS) Role.

To solve this issue just close the Server Manager Windows the tool start the other configuration.