Dynamics CRM
Dynamics CRM
#dynamics-
crm
Table of Contents
About 1
Remarks 2
Versions 2
Examples 2
Examples 3
Known Workarounds: 4
Introduction 5
Examples 5
Chapter 4: CRM 2013: How to hide unwanted Activity Types from the sub grid 8
Introduction 8
Examples 8
Examples 11
Getting accounts 12
Remarks 13
Examples 13
Chapter 7: What Not to do when upgrading your Microsoft Dynamics CRM 2016 15
Introduction 15
Examples 15
Let’s look at some mandatory items to check off before diving into a full-scale upgrade pr 15
Will the benefits of upgrading outweigh the headaches? Is an upgrade worth it? 16
Credits 21
About
You can share this PDF with anyone you feel could benefit from it, downloaded the latest version
from: dynamics-crm
It is an unofficial and free dynamics-crm ebook created for educational purposes. All the content is
extracted from Stack Overflow Documentation, which is written by many hardworking individuals at
Stack Overflow. It is neither affiliated with Stack Overflow nor official dynamics-crm.
The content is released under Creative Commons BY-SA, and the list of contributors to each
chapter are provided in the credits section at the end of this book. Images may be copyright of
their respective owners unless otherwise specified. All trademarks and registered trademarks are
the property of their respective company owners.
Use the content presented in this book at your own risk; it is not guaranteed to be correct nor
accurate, please send your feedback and corrections to [email protected]
https://riptutorial.com/ 1
Chapter 1: Getting started with dynamics-crm
Remarks
Microsoft Dynamics CRM SDK allows developers to extend the Microsoft Dynamics CRM product,
add new functionalities and meet requirements.
The SDK allows you to operate and communicate with the platform programmatically through web
service messages, as well as to add custom code components like plug-ins, custom workflows
and custom actions.
The Microsoft Dynamics CRM provides a JavaScript SDK library called Xrm on the client-side,
which allows extending the user interface and experience.
Versions
Version Sdk Version Download link Release notes link Release Date
Examples
Download Microsoft CRM SDK
The latest SDK libraries are also available on NuGet under Microsoft's official crmsdk account
https://riptutorial.com/ 2
Chapter 2: Bug - TurboForms
Xrm.Page.data.save().then() Errors With
ErrorCode "Null", Message "Undefined"
Examples
onChange() Calls save(), From Field That Is Invalid
function forceSaveOnChangeOfTitle(){
Xrm.Page.data.save().then(
function () {},
function (error, message) {console.error("Error: " + error + " Message: " + message);}
);
https://riptutorial.com/ 3
}
Result:
• Save fails. Calls failure callback with Error Number of "null", and Message of "undefined".
• Field Notification disappears, but required message is still displayed in the bottom right:
Known Workarounds:
Set the value of the attribute to itself:
function forceSaveOnChangeOfTitle(){
var title = Xrm.Page.getAttribute("title");
title.setValue(title.getValue());
Xrm.Page.data.save().then(
function () {},
function (error, message) {console.error("Error: " + error + " Message: " + message);}
);
}
function forceSaveOnChangeOfTitle(){
setTimeout(function() {
Xrm.Page.data.save().then(
function () {},
function (error, message) {console.error("Error: " + error + " Message: " +
message);}
);
}, 1);
}
https://riptutorial.com/ 4
Chapter 3: Call Actions using Web API
Introduction
Examples how to call bound and unbound actions.
Note that in a bound function the full function name includes the namespace
Microsoft.Dynamics.CRM. Functions that aren't bound must not use the full name.
Examples
Call actions using Web API
function exampleQualifyLead(id){
var payload = {
"CreateAccount": createAccount,
"CreateContact": createContact,
"CreateOpportunity": false,
"Status":3
};
https://riptutorial.com/ 5
if (successCallback) {
successCallback(result);
}
} else {
if(errorCallback) {
errorCallback(this);
}
else{
Xrm.Utility.alertDialog(this.statusText);
}
}
}
};
if (payload) {
req.send(JSON.stringify(payload));
}
else {
req.send();
}
}
if (successCallback) {
successCallback(result);
}
} else {
if(errorCallback) {
errorCallback(this);
}
else{
Xrm.Utility.alertDialog(this.statusText);
}
}
}
};
if (payload) {
req.send(JSON.stringify(payload));
}
else {
req.send();
https://riptutorial.com/ 6
}
}
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 { throw new Error("Context is not available."); }
}
}
function getWebAPIPath() {
return getClientUrl() + "/api/data/v8.2/";
}
https://riptutorial.com/ 7
Chapter 4: CRM 2013: How to hide unwanted
Activity Types from the sub grid
Introduction
I recently had to modify the Activity sub-grid to remove certain activity types from the add activity
menu.
Note, this may not be a supported method on how to do this, but there is no documented
supported way to so it, so I had to come up with a solution & this worked, in CRM 2013 anyway.
Examples
Add this function to a javascript web resource
https://riptutorial.com/ 8
{
console.log('menu not found: ' + val);
}
});
}
}
}, 2000);
}
Then call the function from the onload event adding the grid name as a parameter like so
https://riptutorial.com/ 9
Read CRM 2013: How to hide unwanted Activity Types from the sub grid online:
https://riptutorial.com/dynamics-crm/topic/9836/crm-2013--how-to-hide-unwanted-activity-types-
from-the-sub-grid
https://riptutorial.com/ 10
Chapter 5: Using Web API with jQuery
Examples
Using the verbose option to get optionset and lookup values
By default you will get de codes and id's for optionsets and lookups. If you want to get the label as
well, you need to add an extra header to the call.
$.ajax({
url: Xrm.Page.context.getClientUrl() + '/api/data/v8.0/contacts',
headers: {
'Accept': 'Application/json',
'Prefer': 'odata.include-annotations="OData.Community.Display.V1.FormattedValue"'
}
}).done(function (result) {
$.each(result.value, function (key, value) {
//sample to access a label
var gendercodeLabel = value['[email protected]'];
var gendercodeValue = value.gendercode;
});
});
For performance reasons you should minimize the number of fields you are requesting from the
API. You can use the select property to do so.
$.ajax({
url: Xrm.Page.context.getClientUrl() + '/api/data/v8.0/accounts?$select=name',
headers: {
'Accept': 'Application/json'
}
}).done(function (result) {
$.each(result.value, function (key, value) {
var lastname = value.primarycontactid.lastname;
});
});
If you fetch a single record and when that record has a lookup, you can also fetch values of the
lookup value using the expand option. This reduces the number of calls you need to make to the
API.
The sample gets all accounts and the last name of the primary contact:
$.ajax({
https://riptutorial.com/ 11
url: Xrm.Page.context.getClientUrl() +
'/api/data/v8.0/accounts?$select=name,primarycontactid&$expand=primarycontactid($select=lastname)',
headers: {
'Accept': 'Application/json'
}
}).done(function (result) {
$.each(result.value, function (key, value) {
var lastname = value.primarycontactid.lastname;
});
});
Getting accounts
This sample fetches accounts using a jQuery ajax method. On thing to note is that you need to set
the header in the call to make the work.
$.ajax({
url: Xrm.Page.context.getClientUrl() + '/api/data/v8.0/accounts',
headers: {
'Accept': 'Application/json'
}
}).done(function (result) {
var accounts = result.value;
});
You can use the filter property to retrieve a subset of values from CRM. In this example only the
accounts where the company name equals CompanyName are returned.
$.ajax({
url: Xrm.Page.context.getClientUrl() + '/api/data/v8.0/accounts?$filter=name eq
CompanyName',
headers: {
'Accept': 'Application/json'
}
}).done(function (result) {
var accounts = result.value;
});
https://riptutorial.com/ 12
Chapter 6: Web API posts JSON examples
Remarks
Be sure to add the following header to the post request. Otherwise the request will fail:
Content-Type: application/json
Examples
Creating a note / annotation with attachment
url: /api/data/v8.0/annotations
json:
{
"isdocument": true,
"mimetype": "text/plain",
"documentbody": "dGVzdA==",
"[email protected]" : "/accounts(c6da77b6-d53e-e611-80b9-0050568a6c2d)",
"filename": "test.txt"
}
As the objectid can be almost every entity in CRM you need to define the entity with _entity name
after objectid.
Creating an account
url: /api/data/v8.0/accounts
json:
{
"name" : "New account"
}
url: /api/data/v8.0/contacts
json:
{
"firstname" : "New",
"lastname" : "Contact",
"[email protected]" : "/accounts(c6da77b6-d53e-e611-80b9-0050568a6c2d)"
https://riptutorial.com/ 13
}
As the parentcustomerid can be an account or contact you need to define the type of entity you
want to set with _entityname after parentcustomerid.
url: /api/data/v8.0/quotedetails
json:
{
"[email protected]": "/products(11c0dbad-91df-e311-b8e5-6c3be5a8b200)",
"[email protected]" : "/quotes(69b5e1ae-037f-e611-80ed-fc15b428dcdc)",
"[email protected]" : "/uoms(73a5daea-6ddc-e311-a678-6c3be5a8c0e8)",
"quantity": 1
}
https://riptutorial.com/ 14
Chapter 7: What Not to do when upgrading
your Microsoft Dynamics CRM 2016
Introduction
Microsoft Dynamics CRM has evolved drastically over the past few years. There have been many
updates and versions released, with a range of new features and improvements at each stage
along the path. During the upgrade of a Dynamics CRM environment, there are a few points to
bear in mind to ensure a hassle- free upgrade process.
Examples
Let’s look at some mandatory items to check off before diving into a full-scale
upgrade process
DB backup
Database backup is a must before starting any Dynamics CRM upgrade process. This is
mandatory as to always have the option to rollback in case of any major roadblock.
Wrong Estimation
Audit your current Microsoft Dynamics CRM and identify third-party solutions in use. For these
third party solutions, check their developer website for compatibility with your intended upgrade
CRM version. Download the new solution and keep it ready to test after the migration process has
been completed.
CRM Organization
As a first step, we need to prepare the CRM organisation to upgrade Microsoft Dynamics CRM.
Make sure that your CRM environment satisfies the software and hardware component
requirements
While upgrading CRM 4, delete records from listed table. (The system will try to delete all the
records from the below tables when we migrate to CRM 2011, in case it fails then we have to
manually delete the entries from these tables.) Records in the below-listed tables will result in poor
performance of the system.
AsyncOperationBase
https://riptutorial.com/ 15
WorkflowWaitSubscriptionBase
BulkDeleteFailureBase
WorkflowLogBase
DuplicateRecordBase
WorkflowWaitSubscriptionBase
Install the latest rollup before upgrading CRM. For example, in order to upgrade to CRM 2013, the
CRM 2011 Server must either be in Update Rollup 6, Update Rollup 14 or a later rollup before an
upgrade can be considered. Else, while upgrading the Dynamics CRM environment, an error will
be thrown.
For upgrading to MS CRM 2013, use custom code validation tool to check for unsupported client
side codes (JavaScript) that will not work following the upgrade. Also, use the legacy feature
check tool to detect any server extensions that use the 2007 endpoint or Microsoft Dynamics CRM
4.0 features.
Each new version of Microsoft Dynamics CRM introduces more powerful functionalities, but along
with the allure of the latest and greatest version of software, comes the concern of how the
upgrade process will impact your business.
Now, here are some common pitfalls which might come along your way when upgrading your
Dynamics CRM system.
The organisation database selected for the import is a different version than the organisation
database that is currently deployedCRM Organization Database
https://riptutorial.com/ 16
To fix this issue, we need to install either UR6 or above in MS CRM 2011 environment while
upgrading to MS CRM 2013. Following this, the upgrade to Dynamics CRM 2016 can be
completed without concerns
https://riptutorial.com/ 17
To fix this issue, we need to install SP1 for MS CRM 2013. Following this, the upgrade to
Dynamics CRM 2016 can be completed without concerns.
Uninstallation of Microsoft Dynamics CRM connector for SQL Server reporting services
To fix this issue, uninstall Microsoft Dynamics CRM 2013 reporting extensions from Installed
programs in Control panel before proceeding with the upgrade to Dynamics CRM 2016.
The SQL Server Reporting Service account is a local user and is not supported when upgrading
from CRM 2013 to CRM 2015
https://riptutorial.com/ 18
If the Microsoft SQL Server 2012 Reporting Service was installed via default settings – then the
service account is set to “ReportServer” – to resolve the issue, open the Reporting Services
Configuration Manager and update the Service Account to anything else such as “Local System”.
Following this, we won’t face any concerns while we upgrading to MS CRM 2016.
Some of our learning have been simple and logical, but many might forgo them.
https://riptutorial.com/ 19
While upgrading, don’t go with as it is upgraded, there are many features that can cater to the
organisation’s current requirements which are implemented through customization. These can be
modelled out of the box to fit the requirements with later versions.
Also, consider the communication/integration components with which the legacy or any existing
system is connected with Microsoft Dynamics CRM. These are important links which should not be
affected during an upgrade process, and when affected, can greatly impact productivity
Read What Not to do when upgrading your Microsoft Dynamics CRM 2016 online:
https://riptutorial.com/dynamics-crm/topic/9616/what-not-to-do-when-upgrading-your-microsoft-
dynamics-crm-2016
https://riptutorial.com/ 20
Credits
S.
Chapters Contributors
No
Bug - TurboForms
Xrm.Page.data.save().then()
2 Daryl
Errors With ErrorCode
"Null", Message "Undefined"
5 Using Web API with jQuery Arun Vinoth, Daryl, jcjr, Martijn Eikelenboom
https://riptutorial.com/ 21