Search This Blog

Tuesday, March 21, 2017

Dynamics CRM WEB API Generic code

Dynamics CRM WEB API Generic code
"use strict";
var ANK = window.ANK || {};
ANK.WebAPI = ANK.WebAPI || {};
(
    function() {
        this.Retrieve = function(entitySetName, filtersClause, requestHeader, asynch, successCallback, errorCallback) {
                var req = new XMLHttpRequest();

                var filterString = "";
                if (filtersClause != null)
                    filterString = filtersClause;
                var strURL = encodeURI(getWebAPIPath() + entitySetName) + filterString;

                req.open("GET", strURL, asynch);
                req.setRequestHeader("Accept", "application/json");
                req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                req.setRequestHeader("OData-MaxVersion", "4.0");
                req.setRequestHeader("OData-Version", "4.0");
                req.setRequestHeader("Prefer", 'odata.include-annotations="*"');

                if (requestHeader != null && requestHeader != '')
                    setRequestHeader(req);

                req.onreadystatechange = function() {
                    if (this.readyState == 4 /* complete */ ) {
                        req.onreadystatechange = null;
                        if (this.status == 200) {
                            var data = JSON.parse(this.response);

                            if (successCallback)
                                successCallback(data);
                        } else {
                            if (errorCallback)
                                errorCallback(ANK.WebAPI.errorHandler(this.response));
                        }
                    }
                };
                req.send();
            },
            this.UpdateSingleValue = function(entitySetName, PrimaryKeyValue, strPropertyName, objValues, asynch, successCallback, errorCallback) {
                //convert JSON object to string
                var body = JSON.stringify(objValues);
                entitySetName += "(" + PrimaryKeyValue + ")";
                if (strPropertyName == null || strPropertyName == '' || strPropertyName == undefined)
                    strPropertyName = '';

                var req = new XMLHttpRequest();

                req.open("PUT", encodeURI(getWebAPIPath() + entitySetName + "/" + strPropertyName), asynch);
                req.setRequestHeader("Accept", "application/json");
                req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                req.setRequestHeader("OData-MaxVersion", "4.0");
                req.setRequestHeader("OData-Version", "4.0");
                req.onreadystatechange = function() {
                    if (this.readyState == 4 /* complete */ ) {
                        req.onreadystatechange = null;
                        if (this.status == 204) {

                            var ObjectUri = this.getResponseHeader("OData-EntityId");
                            var ObjectID = '';
                         
                            if (ObjectUri != null) {
                                //get EntityId from ResponseHeader of Created Record
                                ObjectID = ObjectUri.split(/[()]/);
                                ObjectID = ObjectID[1];
                            }
                            if (successCallback)
                                successCallback(ObjectID);

                        } else {
                            if (errorCallback)
                                errorCallback(ANK.WebAPI.errorHandler(this.response));
                        }
                    }
                };
                req.send(body);
            },
            this.Update = function(entitySetName, PrimaryKeyValue, objValues, asynch, successCallback, errorCallback) {
                //convert JSON object to string
                var body = JSON.stringify(objValues);
                entitySetName += "(" + PrimaryKeyValue + ")";
                var req = new XMLHttpRequest();

                req.open("PATCH", encodeURI(getWebAPIPath() + entitySetName), asynch);
                req.setRequestHeader("Accept", "application/json");
                req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                req.setRequestHeader("OData-MaxVersion", "4.0");
                req.setRequestHeader("OData-Version", "4.0");
                req.onreadystatechange = function() {
                    if (this.readyState == 4 /* complete */ ) {
                        req.onreadystatechange = null;
                        if (this.status == 204) {

                            var ObjectUri = this.getResponseHeader("OData-EntityId");

                            //get EntityId from ResponseHeader of Created Record
                            var ObjectID = ObjectUri.split(/[()]/);
                            ObjectID = ObjectID[1];
                            if (successCallback)
                                successCallback(ObjectID);

                        } else {
                            if (errorCallback)
                                errorCallback(ANK.WebAPI.errorHandler(this.response));
                        }
                    }
                };
                req.send(body);
            },

            this.Delete = function(entitySetName, PrimaryKeyValue, asynch, successCallback, errorCallback) {

                entitySetName += "(" + PrimaryKeyValue + ")";
                var req = new XMLHttpRequest();

                req.open("DELETE", encodeURI(getWebAPIPath() + entitySetName), asynch);
                req.setRequestHeader("Accept", "application/json");
                req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                req.setRequestHeader("OData-MaxVersion", "4.0");
                req.setRequestHeader("OData-Version", "4.0");
                req.onreadystatechange = function() {
                    if (this.readyState == 4 /* complete */ ) {
                        req.onreadystatechange = null;
                        if (this.status == 204) {

                            if (successCallback)
                                successCallback();
                        } else {
                            if (errorCallback)
                                errorCallback(ANK.WebAPI.errorHandler(this.response));
                        }
                    }
                };
                req.send();
            },


            this.Create = function(entitySetName, entity, successCallback, errorCallback) {
                var req = new XMLHttpRequest();
                req.open("POST", encodeURI(getWebAPIPath() + entitySetName), true);
                req.setRequestHeader("Accept", "application/json");
                req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                req.setRequestHeader("OData-MaxVersion", "4.0");
                req.setRequestHeader("OData-Version", "4.0");

                req.onreadystatechange = function() {
                    if (this.readyState == 4 /* complete */ ) {
                        req.onreadystatechange = null;


                        if (this.status == 204) {
                            if (successCallback)
                                successCallback(this.getResponseHeader("OData-EntityId"));
                        } else {
                            if (errorCallback)
                                errorCallback(MyNameSpace.WebAPI.errorHandler(this.response));
                        }
                    }
                };
                req.send(JSON.stringify(entity));
            };

        function setRequestHeader(req) {
            for (var key in headers) {
                req.setRequestHeader(key, headers[key]);
            }
        }
        //Internal supporting functions
        function getClientUrl() {

            //Get the organization URL
            if (typeof GetGlobalContext == "function" &&
                typeof GetGlobalContext().getClientUrl == "function") {
                return GetGlobalContext().getClientUrl();
            } else {
                //If GetGlobalContext is not defined check for Xrm.Page.context;
                if (typeof Xrm != "undefined" &&
                    typeof Xrm.Page != "undefined" &&
                    typeof Xrm.Page.context != "undefined" &&
                    typeof Xrm.Page.context.getClientUrl == "function") {
                    try {
                        return Xrm.Page.context.getClientUrl();
                    } catch (e) {
                        throw new Error("Xrm.Page.context.getClientUrl is not available.");
                    }
                } else if (typeof parent.Xrm != "undefined" &&
                    typeof parent.Xrm.Page != "undefined" &&
                    typeof parent.Xrm.Page.context != "undefined" &&
                    typeof parent.Xrm.Page.context.getClientUrl == "function") {
                    try {
                        return parent.Xrm.Page.context.getClientUrl();
                    } catch (e) {
                        throw new Error("parent.Xrm.Page.context.getClientUrl is not available.");
                    }
                } else {
                    throw new Error("Context is not available.");
                }
            }
        }

        function getWebAPIPath() {
            return getClientUrl() + "/api/data/v8.0/";
        }

        // This function is called when an error callback parses the JSON response
        // It is a public function because the error callback occurs within the onreadystatechange
        // event handler and an internal function would not be in scope.
        this.errorHandler = function(resp) {
            try {
                return JSON.parse(resp).error;
            } catch (e) {
                return new Error("Unexpected Error")
            }
        }

    }).call(ANK.WebAPI);

CRM Web API Odata query

CRM Web API Odata query


Expand:
Single value Navigation:
On the entity Account entity, contact lookup  schema name should be given

Collection Navigation:
on the entity Account entity: 1:n relationship name

Monday, March 20, 2017

Update OWNER field in CRM work flow

We would need to update any entity "owner" field in work flow. But in the workflow owner field is locked.
Instead of using "update" step in the work flow use "Assign" step
Now your workflow change the owner field.

Sunday, March 19, 2017

Compatibility with Microsoft Dynamics CRM 2011 Introduction

ProductMinimum CRM versionCRM build numberStatus
.Net Framework 4.0RTM5.0.9688.583Compatible
.Net Framework 4.0 PU3--TBD
.Net Framework 4.5Update Rollup 85.0.9690.2243Compatible
.Net Framework 4.5.1Update Rollup 155.0.9690.3731Compatible
.Net Framework 4.5.2Update Rollup 175.0.9690.4150Compatible
.Net Framework 4.6--TBD
Active Directory Federation Services in Windows Server 2008 (AD FS 2.0)RTM5.0.9688.583Compatible
Active Directory Federation Services in Windows Server 2008 R2RTM5.0.9688.583Compatible
Active Directory Federation Services in Windows Server 2012Update Rollup 135.0.9690.3432Compatible
Active Directory Federation Services in Windows Server 2012 R2--Not compatible
Azure virtual machines (support for Microsoft Azure virtual machines)--Not compatible
Exchange Online (O365)Update Rollup 55.0.9688.1533Compatible
Exchange Online (BPOS)RTM5.0.9688.583Compatible
Exchange Server 2000--Not compatible
Exchange Server 2003 SP2RTM5.0.9688.583Compatible
Exchange Server 2003 SP3RTM5.0.9688.583Compatible
Exchange Server 2007RTM5.0.9688.583Compatible
Exchange Server 2010RTM5.0.9688.583Compatible
Exchange Server 2010 SP1Update Rollup 125.0.9690.3236Compatible
Exchange Server 2010 SP2Update Rollup 125.0.9690.3236Compatible
Exchange Server 2010 SP3Update Rollup 135.0.9690.3448Compatible
Exchange Server 2013Update Rollup 155.0.9690.3731Compatible
Exchange Server 2013 SP1Update Rollup 185.0.9690.4376Compatible
FirefoxUpdate Rollup 125.0.9690.3236Compatible
Google ChromeUpdate Rollup 125.0.9690.3236Compatible
Internet Explorer 6 (no longer supported)--Not compatible
Internet Explorer 7 (no longer supported)RTM5.0.9688.583Compatible
Internet Explorer 8 (no longer supported)RTM5.0.9688.583Compatible
Internet Explorer 9 (no longer supported)RTM5.0.9688.583Compatible
Internet Explorer 10 (no longer supported)Update Rollup 105.0.9688.2730Compatible
Internet Explorer 11Update Rollup 175.0.9690.4150Compatible
Microsoft Application Virtualization (App-V) 4.6--Not compatible
Microsoft Office Communications Server 2007RTM5.0.9688.583Compatible
Microsoft Office Communications Server 2007 R2RTM5.0.9688.583Compatible
Microsoft Report Viewer 2010RTM5.0.9688.583Compatible
Microsoft SharePoint 2010 (all editions)RTM5.0.9688.583Compatible
Microsoft SharePoint 2013Update Rollup 125.0.9690.3236Compatible
Microsoft Office SharePoint Server 2007RTM5.0.9688.583Compatible
Microsoft Visual C++ Redistributable 2008RTM5.0.9688.583Compatible
Microsoft Visual C++ Redistributable 2010Update Rollup 65.0.9690.1992Compatible
Microsoft Windows Installer (MSI) 4.5RTM5.0.9688.583Compatible
MSXML 4.0RTM5.0.9688.583Compatible
Office 2003 SP3 (no longer supported)RTM5.0.9688.583Compatible
Office 2007 SP2 (Cached-Exchange Mode Only)RTM5.0.9688.583Compatible
Office 2007 SP3 (Cached-Exchange Mode Only)Update Rollup 55.0.9688.1533Compatible
Office 2010 (Cached-Exchange Mode Only)RTM5.0.9688.583Compatible
Office 2010 SP1 (Cached-Exchange Mode Only)RTM5.0.9688.583Compatible
Office 2010 SP2 (Cached-Exchange Mode Only)Update Rollup 155.0.9690.3731Compatible
Office 2013 MSI (Cached-Exchange Mode Only)Update Rollup 105.0.9688.2730Compatible
Office 2013 C2R (stand-lone) (Cached-Exchange Mode Only)Update Rollup 105.0.9688.2730Compatible
Office 2013 C2R (side-by-side with Office 2010)(Cached-Exchange Mode Only)Update Rollup 105.0.9688.2730Compatible
Office 2013 SP1 (Cached-Exchange Mode Only)Update Rollup 175.0.9690.4150Compatible
Office 2016 (MSI install only) (Cached-Exchange Mode Only)Update Rollup 185.0.9690.4376Compatible
SafariUpdate Rollup 125.0.9690.3236Compatible
SharePoint 2013Update Rollup 125.0.9690.3236Compatible
Small Business Server 2008 Premium (x64)RTM5.0.9688.583Compatible
Small Business Server 2008 Standard (x64)RTM5.0.9688.583Compatible
Small Business Server 2008 StandardRTM5.0.9688.583Compatible
Small Business Server 2011 EssentialsUpdate Rollup 35.0.9688.1244Compatible
SQL Server 2000--Not Compatible
SQL Server 2005--Not compatible
SQL Server 2008 Express Edition SP1RTM5.0.9688.583Compatible
SQL Server 2008 Standard SP1 (x64)RTM5.0.9688.583Compatible
SQL Server 2008 SP2 (x64)Update Rollup 85.0.9690.2243Compatible
SQL Server 2008 SP3 (x64)Update Rollup 85.0.9690.2243Compatible
SQL Server 2008 R2 (x64)RTM5.0.9688.583Compatible
SQL Server 2008 R2 SP1 (x64)Update Rollup 85.0.9690.2243Compatible
SQL Server 2008 R2 SP2 (x64)Update Rollup 85.0.9690.2243Compatible
SQL Server 2008 R2 SP2 (CTP) (x64)Update Rollup 85.0.9690.2243Compatible
SQL Server 2008 R2 SP3Update Rollup 185.0.9690.4376Compatible
SQL Server 2008 Reporting Services (pre-Update Rollup 17)RTM5.0.9688.583Compatible
SQL Server 2008 Reporting Services (post-Update Rollup 17)--Not Compatible
SQL Server 2008 R2 Reporting ServicesRTM5.0.9688.583Compatible
SQL Server Compact 3.5 SP2RTM5.0.9688.583Compatible
SQL Server Compact 4.0Update Rollup 45.0.9688.1450Compatible
SQL Server Active/Active Cluster**Update Rollup 15.0.9688.1045Compatible
SQL Server 2012****Update Rollup 65.0.9690.1992Compatible
SQL Server 2012 SP1Update Rollup 105.0.9688.2730Compatible
SQL Server 2014--TBD
Windows 7 (32bit and 64bit)RTM5.0.9688.583Compatible
Windows 7 SP1RTM5.0.9688.583Compatible
Windows 8 (requires manual WIF enablement)Update Rollup 105.0.9688.2730Compatible
Windows 8.1Update Rollup 175.0.9690.4150Compatible
Windows 10Update Rollup 175.0.9690.4150Compatible
Windows RT--Not compatible
Windows Server 2003--Not compatible
Windows Server 2008 Standard SP2 (x64)RTM5.0.9688.583Compatible
Windows Server 2008 Standard R2RTM5.0.9688.583Compatible
Windows Server 2008 Enterprise SP2 (x64)RTM5.0.9688.583Compatible
Windows Server 2008 Enterprise R2RTM5.0.9688.583Compatible
Windows Server 2008 Datacenter SP2 (x64)RTM5.0.9688.583Compatible
Windows Server 2008 Datacenter R2RTM5.0.9688.583Compatible
Windows Web Server 2008 SP2 (x64) (front-end role only)RTM5.0.9688.583Compatible
Windows Web Server 2008 R2 (front-end role only)RTM5.0.9688.583Compatible
Windows Server 2012 Datacenter or StandardUpdate Rollup 135.0.9690.3432Compatible
Windows Server 2012 R2 Datacenter or Standard--Not compatible
Windows Web Server 2008 SP2 (x64) (front-end role only)RTM5.0.9688.583Compatible
Windows Web Server 2008 R2 (front-end role only)RTM5.0.9688.583Compatible
Windows Vista (x86 and x64)RTM5.0.9688.583Compatible
Windows XP SP3 (no longer supported)RTM5.0.9688.583Compatible

** Active/Active Clustering is supported, but not as a load-balancing configuration.

For a list of support web browsers with Microsoft Dynamics CRM 2011, please see the following link:

Browser compatibility with Microsoft Dynamics CRM 2011 

Notes

  • 32-bit versions of Microsoft SQL Server and SQL Server Reporting Services (SSRS) are not supported.
  • Windows Server 2008 installed by using the Server Core installation option is not supported for installing and running Microsoft Dynamics CRM Server 2011.
  • Microsoft SQL Server 2008 Workgroup and Web, Compact, and Express editions of Microsoft SQL Server 2008 are not supported for running Microsoft Dynamics CRM Server 2011.
  • Windows Server 2008 for Itanium-based systems is not supported for installing and running Microsoft Dynamics CRM 2011
  • The CRM for Outlook client does not support Outlook configured in Online for tracking or synchronization (non-Cached Exchange mode)


For more information about System Requirements, see the System Requirements and Required Components topic in the Microsoft Dynamics CRM 2011 Implementation Guide.