CRM Online to SharePoint Online Integration using REST and ADFS

Accessing SharePoint Online 2013 REST services with SSO via ADFS (Active Directory Federation Services) from CRM Online provides loads of potential opportunities, especially now that SharePoint offers a huge REST API. You can call REST from a CRM Online Plugin or Custom Workflow activity with no dependencies on SharePoint Client dll’s or Azure getting in the way, It is fairly awesome I must say.

I use the HttpWebRequest class to perform SOAP requests to perform the authentication part of this integration, which is totally supported within Sandboxed Plugins and Custom Workflow Activities. You can read more about the restrictions of the CRM Sandboxed environment here http://msdn.microsoft.com/en-us/library/gg334752.aspx. Once you get authenticated and obtain the cookies you are free to fire REST calls off by simply providing the cookies along with the request.

The best diagram I found to describe the authentication process visually was from Wictor Wilen’s blog http://www.wictorwilen.se/

Auth Process

I wanted to explore the issue of authentication between CRM Online and SharePoint Online from a server to server perspective and as you can imagine authentication is a big hurdle for this direct type of communication as every example I have seen so far includes Azure. Well at least until I started to look at what others were doing with Windows 8 Apps and Active Authentication. Omar Venado http://blogs.msdn.com/b/omarv/ and fellow MVP Wictor Wilen http://www.wictorwilen.se/ had some really great articles to help me build out a solution focused on this scenario. The code attached to this blog is heavily derived from Omar’s Windows 8 App code though now is useable in non Windows 8 App projects such as C# Console, SSIS Packages and of course CRM Plugin/Workflow projects. I have added some background reading at the bottom of this post so you can see the articles I used to get my code to work.

An example of how simple this code is to use

Uri spSite = new Uri(https://myOrg.sharepoint.com/sites/mySite”);

bool success = SpoAuthUtility.Create(spSite, username@domain.com, WebUtility.HtmlEncode(“Pword123″), false);

string odataQuery = “_api/web/lists”;

Uri url = new Uri(String.Format(“{0}/{1}”, SpoAuthUtility.Current.SiteUrl, odataQuery));

// Send a json odata request to SPO rest services to fetch all list items for the list.

byte[] result = HTTPHelper.SendODataJsonRequest(

url,

“GET”, // reading data from SP through the rest api usually uses the GET verb

null,

(HttpWebRequest)HttpWebRequest.Create(url),

SpoAuthUtility.Current // pass in the helper object that allows us to make authenticated calls to SPO rest services

);

string response = Encoding.UTF8.GetString(result, 0, result.Length);

You can authenticate using corporate credentials if inside your network, username/password if outside your network (e.g CRM Online O365) and you can also use your onmicrosoft.com accounts. Remember that my primary focus was on server to server integration possibilities, not user to server contexts such as in the current SharePoint CRM List Component model.

The attached C# Console app contains 3 files to provide you with an example of how to use the 2 cs classes HTTPHelper and SPOAuthUtility. To authenticate and start calling REST from CRM Plugins/Workflows simple include the HTTPHelper and SPOAuthUtility cs files into your Plugin/Workflow project.

Example App is available here https://skydrive.live.com/redir?resid=492A170E77E43399!830

Background reading

http://blogs.msdn.com/b/omarv/archive/2012/10/25/windows-8-store-apps-office-365-enterprise-preview-sharepoint-online.aspx

http://blogs.msdn.com/b/omarv/archive/2012/11/15/developing-windows-store-apps-for-sharepoint-online-with-sso-single-sign-on.aspx

http://www.wictorwilen.se/Post/How-to-do-active-authentication-to-Office-365-and-SharePoint-Online.aspx

http://allthatjs.com/2012/03/28/remote-authentication-in-sharepoint-online/

CRM 2011 SDK version 5.0.16 available

The MS CRM Team have released an updated CRM 2011 SDK version 5.0.16 which can be downloaded here http://www.microsoft.com/en-us/download/details.aspx?id=24004 or viewed on MSDN here http://msdn.microsoft.com/en-us/library/gg309408.aspx Check out the SDK Release History notes here http://msdn.microsoft.com/en-us/library/dn198205.aspx

 

What’s Changing in the Next Major Release – This new topic outlines features that will be changing in the upcoming Orion release and provides a tool you can use to help you prepare your organizations for these changes.

 

New and updated topics Description of changes
Microsoft_Dynamics_CRM_2011_SDK_Readme.htm Updated the readme for this version of the SDK package.
Active Directory and Claims-Based Authentication

Authenticate Office 365 Users with Microsoft Dynamics CRM Online Web Services

OrganizationServiceProxy

DiscoveryServiceProxy

Updated these topics to remove the restriction on using the service proxy classes when authenticating with the Microsoft online services identity provider of Microsoft Dynamics CRM Online. You can now use these proxy classes with all deployment types and identity providers.
BulkDeleteRequest

BulkDetectDuplicatesRequest

Added in Remarks that you can run the bulk delete job or bulk detect duplicates job daily or without recurrence.
Create, Export, or Import an Unmanaged Solution

Create, Install, and Update a Managed Solution

Added a note to these topics saying “Installing a solution can interfere with normal system operation. We recommend that you schedule solution imports when it’s least disruptive to users.”
Form XML Reference The following FormXml elements have been updated to indicate that they are for internal use only: <ControlMode> (FormXml), <QuickFormRelationshipName> (FormXML), <QuickFormRelationshipRoleOrdinal> (FormXml), and <UniqueId> (FormXml). These elements are used only in a quick form, which is not customizable. These elements will be removed from the schema in the next major release.
Handle Exceptions in Plug-Ins Clarified how plug-in exceptions are handled and where error message are written or displayed.
Introduction to Activity Feeds Corrected the maximum number of characters in the posts created programmatically. The correct value is 2000 characters.
Introduction to Solutions Added the Enterprise Solution Lifecycle Management section introducing the ALM for Microsoft Dynamics CRM 2011: CRM Solution Lifecycle Management white paper.
Open Forms, Views, Dialogs and Reports with a URL Appended to an existing note to include:

Microsoft Dynamics CRM forms are not designed to be opened as dialogs using either showModalDialog or showModelessDialog.

Uninstall or Delete a Solution Added an Access the Solutions List with a URL section.
What’s Changing in the Next Major Release Added a new topic to provide information about what is changing in the next major release of Microsoft Dynamics CRM.
Write Custom Code for Microsoft Dynamics CRM for Outlook

GoOffline               GoOnline

Added a note that these methods cannot be used in a plug-in because they cause a UI interaction with the user.
Xrm.Page.data.entity Attribute Methods Added a missing getFormat return value: textarea.
Xrm.Page.ui Control Methods Added a remark to the addCustomView method to show that this method does not work with Owner lookups.
Xrm.Utility Reference Corrected an error for the openEntityForm method. This method returns a Boolean value rather than a window object.

CRM 2011 Validate User Security Roles using JavaScript/REST

This example I’m sharing today is demonstrating a few techniques which promote JavaScript and REST, along with using namespaces and creating a library of functions/properties. This example declares a library Security.UserInRole and defines a number of properties and functions. The general idea is to allow the data access via REST to be asynchronous which then offers a valid and invalid function callback option to be defined to handle the outcome. You can specify an array of security roles to check against the current user and then with the callback functions you can perform the actions that you require.

Ideally I want to call a function that is easy to use and it will look like this.
Security.UserInRole.checkUserInRole(
["System Administrator", "System Customizer", "Custom Role Name"],
function(){alert("valid"); // The user is in one of the specifed roles.
},
function(){alert("invalid"); // The user is not in one of the specifed roles.
}
}

To define the library namespace and object we use
//If the Security namespace object is not defined, create it.
if (typeof (Security) == "undefined")
{ Security = {}; }
// Create Namespace container for functions in this library;
if (typeof (Security.UserInRole) == "undefined") {
Security.UserInRole = {
__namespace: true
};
}

 

The library functions and properties declared include the following
Security.UserInRole = {
isInRole: null,
roleIdValues: [],
validFunction: null,
invalidFunction: null,
checkRoles: [],
checkUserInRole: function (roles, validFunc, invalidFunc) {},
getAllowedSecurityRoleIds: function () {},
validateSecurityRoles: function () {},
querySecurityRoles: function (queryString) {},
__namespace: true
};

 

The entire library is implemented so that you call a function, it performs the processing asynchronously and then gives you the outcome to handle the response. Whether you want to show/hide form elements or disable fields etc, you can handle this in the callback function parameters validFunc and invalidFunc defined in the checkUserInRole function. The entire library content can be placed in a CRM webresource and added to a form. The full library is as shown below.

//If the Security namespace object is not defined, create it.
if (typeof (Security) == "undefined")
{ Security = {}; }
// Create Namespace container for functions in this library;
if (typeof (Security.UserInRole) == "undefined") {
Security.UserInRole = {
isInRole: null,
roleIdValues: [],
validFunction: null,
invalidFunction: null,
checkRoles: [],
checkUserInRole: function (roles, validFunc, invalidFunc) {
validFunction = validFunc;
invalidFunction = invalidFunc;
checkRoles = roles;
Security.UserInRole.getAllowedSecurityRoleIds();
},
getAllowedSecurityRoleIds: function () {
var filter = "";
for (var i = 0; i < checkRoles.length; i++) {
if(filter == "") {
filter = "Name eq '" + checkRoles[i] + "'";
}
else {
filter += " or Name eq '" + checkRoles[i] + "'";
}
}
Security.UserInRole.querySecurityRoles("?$select=RoleId,Name&$filter=" + filter);
},
validateSecurityRoles: function () {
switch (Security.UserInRole.isInRole) {
//If the user has already been discovered in role then call validFunc
case true:
validFunction.apply(this, []);
break;
default:
var userRoles = Xrm.Page.context.getUserRoles();
for (var i = 0; i < userRoles.length; i++) {
var userRole = userRoles[i];
for (var n = 0; n < Security.UserInRole.roleIdValues.length; n++) {
var role = Security.UserInRole.roleIdValues[n];
if (userRole.toLowerCase() == role.toLowerCase()) {
Security.UserInRole.isInRole = true;
// Call function when role match found
validFunction.apply(this, []);
return true;
}
}
}
// Call function when no match found
invalidFunction.apply(this, []);
break;
}
},
querySecurityRoles: function (queryString) {
var req = new XMLHttpRequest();
var url = "";
// Try getClientUrl first (available post Rollup 12)
if (Xrm.Page.context.getClientUrl) {
url = Xrm.Page.context.getClientUrl();
}
else {
url = Xrm.Page.context.getServerUrl();
}
req.open("GET", url + "/XRMServices/2011/OrganizationData.svc/RoleSet" + queryString, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null; //Addresses memory leak issue with IE.
if (this.status == 200) {
var returned = window.JSON.parse(this.responseText).d;
for (var i = 0; i < returned.results.length; i++) {
Security.UserInRole.roleIdValues.push(returned.results[i].RoleId);
}
if (returned.__next != null) {
//In case more than 50 results are returned.
// This will occur if an organization has more than 16 business units
var queryOptions = returned.__next.substring((url + "/XRMServices/2011/OrganizationData.svc/RoleSet").length);
Security.UserInRole.querySecurityRoles(queryOptions);
}
else {
//Now that the roles have been retrieved, try again.
Security.UserInRole.validateSecurityRoles();
}
}
else {
var errorText;
if (this.status == 12029)
{ errorText = "The attempt to connect to the server failed."; }
if (this.status == 12007)
{ errorText = "The server name could not be resolved."; }
try {
errorText = window.JSON.parse(this.responseText).error.message.value;
}
catch (e)
{ errorText = this.responseText }
}
}
};
req.send();
},
__namespace: true
};
}

 

To use the library in the onload event of an entity form simply add the Security.UserInRole library webresource to the form and create a another JavaScript web resource to hold the onload function. The onload function may look like this. You define the roles to check as an array and pass this to the checkUserInRole function along with the valid and invalid callback functions. You don’t have to define the functions as anonymous functions like my example below but it can sometimes feel cleaner.

function onload()
{
Security.UserInRole.checkUserInRole(
["System Administrator", "System Customizer", "Custom Role Name"],
function(){alert("valid"); // The user is in one of the specifed roles.
},
function(){alert("invalid"); // The user is not in one of the specifed roles.
}
);
}

 

I would like to mention Jim Daly from the MS CRM Team for his examples of namespace and library structure along with his REST query code as this example I have created is derived from his outstanding work.

Happy Coding..

CRM 2011 Rollup 12 now available

The Microsoft Dynamics CRM Sustained Engineering (SE) team have been hard at work to get the UR12 release to us on Jan 7 2013.

You can find the related Rollup 12 items here

Rollup 12 Build Number: 5.0. 9690.3218

Quick Summary

http://msdn.microsoft.com/en-us/library/gg309589.aspx#BKMK_UR5

  • Extended Browser Support
  • Enhancements to Activity Feeds
  • Updated User Experience for Sales and Customer Service and Product Update Functionality
  • Custom Workflow Activities for Microsoft Dynamics CRM Online
  • Developer Toolkit Support for Microsoft Visual Studio 2012
  • Retrieve and Detect Changes to Metadata
  • Use Execute Multiple to Improve Performance for Bulk Data Load

CRM 2011 SDK version 5.0.13 available

The MS CRM Team have released an updated CRM 2011 SDK version 5.0.13 which can be downloaded here http://www.microsoft.com/en-us/download/details.aspx?id=24004 or viewed on MSDN here http://msdn.microsoft.com/en-us/library/gg309408.aspx Check out the release notes here http://msdn.microsoft.com/en-us/library/jj863620.aspx

Quick Overview

  • Custom workflow activities can now be registered in the sandbox and are supported by Microsoft Dynamics CRM Online.
  • The Developer Toolkit for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online now supports Microsoft Visual Studio 2012.
  • Added information about the new getClientUrl method. This method returns the base URL that was used to access the application. This is now the recommended method to use to access the organization URL. The getServerUrl method is deprecated.
  • Updated the metadata browser to version 2.0
  • Added a new topic for the new metadata query capabilities included in the Microsoft.Xrm.Sdk.Metadata.Query namespace.
  • Updated the topic to include information related to support for browsers other than Internet Explorer.
  • Added information about the new Like/Unlike feature. Updated information about default number of records that you can follow, and the maximum allowed number of characters in the post and the post comment. Also, updated configuration information about obtaining full functionality for activity feeds.
  • Updated exported ribbon definitions for Microsoft Dynamics CRM 2011
  • Added support for the Microsoft online services environment to connect to Microsoft Office 365.
  • Added a new topic to address issues related to solution development when Microsoft Dynamics CRM Online includes features that cannot be enabled in an on-premises deployment of Microsoft Dynamics CRM 2011.
  • Added a note to the Export an Unmanaged Solution section to indicate that, after Microsoft Dynamics CRM 2011 Update Rollup 12 and Microsoft Dynamics CRM December 2012 Service Update, un-customized form definitions will no longer be exported with unmanaged solutions.
  • Added new and updated information about using Windows Azure with Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online.
  • Added a new sample to show a way to deal with the situation where portions of the Xrm.Page object load into the updated forms asynchronously so they may not be available to scripts in HTML web resources at load time.
  • Updated these samples to build with newer versions of the Windows Azure SDK, version 1.7 or 1.8.
  • A bunch of sdk samples have been added and others updated.

Prepare for Dynamics CRM Rollup 12

Are you ready for the multi browser support of your customisations with Dynamics CRM Rollup 12, do you even care? It sounds great doesn’t it, IE, Chrome, Safari, Firefox, take your pick but will your CRM script customisations be supported. I guarantee this is the number one question facing CRM implementers/developers/testers right now and hopefully most have had a chance to test against the latest build of Rollup 12.

If you are a single browser environment and it remains as IE then you may be feeling comfortable but I recommend you follow-up with some testing and review time before applying Rollup 12.

There are some key areas that need looking at and you can find a list of impacted areas here

Resolve Breaking Script Issues When Upgrading Microsoft Dynamics CRM

 

To aid in the validation there is a tool available from Microsoft called the Microsoft Dynamics CRM 2011 Custom Code Validation Tool  which helps to identify potential issues with custom JavaScript in JavaScript libraries and HTML web resources.

To see an overview of problem areas you can see the release blog regarding the validation tool which highlights and lists the various potential issues that have been identified.

Microsoft Dynamics CRM 2011 Custom Code Validation Tool Released

 

The biggest threat to some may be the support of CRM 4 client side script or the lack there of as this becomes obsolete and unsupportable as CRM moves forward.

In many cases business requirements come first and in a perfect world we would never need to venture outside of the CRM 2011 client API so the main thought here should be before implementing unsupported customisations ask yourself if there is an alternative option to avoid future pain.

Don’t forget to check out the latest SDK when its available and read through the documentation covering this as it’s fairly complete and highly detailed for our needs.

The CRM Field Guide – How to CRM like an MVP

http://www.crmfieldguide.com/

The CRM Field Guide is an essential guide to Microsoft Dynamics CRM that everyone should have on their bookshelf.  This book offers you details not only on CRM fundamentals and extensibility points but also the tried and true best practices and strategies of the combined experience of some of the most recognizable global experts in the CRM industry.  The field guide contains insights from many CRM MVP contributors and is intended to be a book you pick up over and over again as you use CRM.

Having the CRM Field Guide by your side is like having the “hotline” to the industry experts.  When you hear the term Field Guide you likely think of nature; identifying key plants or animals in a new and exciting place.  Obviously this book is not that type of a guide.  This book is what you pick up when it’s Friday night and you are stuck with one last CRM problem between you and the weekend.

The CRM Field Guide is not a reference repeating all the contents of the CRM documentation, but it is designed to complement what Microsoft provides offering insights from real world deployments of Microsoft Dynamics CRM.   There’s so much content in the CRM Field Guide, one of the MVPs joked it could probably have enough weight to hold down your desk if a tornado passes through your office!

In the CRM Field Guide you will find details that can help administrators, customizers and developers; not to mention power business users wanting to know all the details the admin never tells them.  If you run CRM in the cloud or sitting in a server room at your office the information is useful.

 

19 Dynamics CRM MVP authors tells you a lot and nearing 1000 pages it is packed full of goodness.

Authors

  1. Joel Lindstrom
  2. Richard Knudson
  3. Donna Edwards
  4. Julie Yack
  5. Pablo Peralta
  6. Rhett Clinton
  7. Jakub Skalbania
  8. Feridun Kadir
  9. Shan McArthur
  10. David Berry
  11. Larry Lentz
  12. Leon Tribe
  13. Scott Sewell
  14. Alex Fagundes
  15. David Yack
  16. Neil Benson
  17. Mitch Milam
  18. Jerry Weinstock
  19. Giorgio Garcia-Agreda

 

Chapter Overview

Chapter 1 - Building the Foundation – This chapter lays the groundwork for understanding the various terms and parts of a CRM Organization. It includes helpful tips not covered elsewhere in the book.

Chapter 2 - CRM Server Installation & Configuration – Learn the requirements, the planning steps, and the process for installing and configuring your CRM server.

Chapter 3 – CRM Outlook Client Installation & Configuration – addresses the different choices and troubleshooting techniques for installation and configuration of Dynamics CRM Outlook Client.

Chapter 4 - CRM 4 Upgrade to CRM 2011 – In this chapter you’ll learn the software and hardware requirements, develop an upgrade plan, prepare your database, upgrade customizations, perform and test the upgrade and train your users.

Chapter 5 – E-mail Router Installation & Troubleshooting – covers the necessity of the e-mail router, the deployment wizard, the configuration manager, hardware and software requirements, installation and configuration and user settings for the e-mail router.

Chapter 6 - Security Best Practices – covers the why and the how of security in Dynamics CRM, including the security tools already built in to CRM as well as a look at special case handling.

Chapter 7 - Sales Management Best Practices – examines critical success factors for sales management, activity and lead management, customer, opportunity and pipeline management, and workflows and sales processes.

Chapter 8 - Service Management Best Practices  -explains the optimal use of cases, contracts, articles, service scheduling and the service calendar.

Chapter 9 – Marketing Management Best Practices – is a detailed look at the benefits of CRM’s marketing tools, including marketing lists and campaigns, as well as campaign reporting.

Chapter 10 – The Power of CRM & Outlook  - explores the benefits of integrating and synchronizing CRM and Outlook and explains how to make it happen and make the most use of the combined tools.

Chapter 11 – Dynamics CRM Goal Management – is an in-depth look at the foundations of goal management, ranging from Sales to Marketing to Service and beyond.

Chapter 12 – Processes –  delves into the power and scope of Workflows and Dialogs, how they work and how you can use them for maximum benefit.

Chapter 13 – Aligning Reports to the Audience  – helps the reader understand and meet the needs of different users and stakeholders by exploring the varying needs and expectations of users and using the array of out-of-the-box tools. (Note: My personal favorite chapter)

Chapter 14 – Report Development – shows how to create the best (read: most useful) reports by utilizing SQL, FetchXML and other tools to build custom reports in CRM.

Chapter 15 – SharePoint & CRM: Better Together – discusses the benefits of SharePoint collaboration tools being integrated with CRM in order to provide the 360° view of the customer, including how to set up integration and how to access CRM from SharePoint.

Chapter 16 – CRM Outlook Optimization & Troubleshooting - examines what you can do to optimize the performance of the Outlook client and how to troubleshoot CRM for Outlook.

Chapter 17 – CRM Server Optimization, Maintenance & Monitoring – covers CRM server, IIS, and SQL server optimization, as well as maintenance and monitoring of the servers.

Chapter 18 – Data Management Best Practices – explores using the Data Import Wizard, duplicate detection, and bulk deletion, plus best practices for ensuring high-quality data in your CRM system.

Chapter 19 – User Adoption – shares key concepts and strategies for encouraging and improving user adoption within you organization.

Chapter 20 – Customization Strategies – discusses a variety of strategies that can be used to customize CRM to fit your business needs and reviews the solution architecture and management.

Chapter 21 – Introduction to Solutions – gives details on custom solutions and components, managed vs. unmanaged solutions, the importing and exporting of solutions, deleting solutions and managed properties.

Chapter 22 – Solution Management and Troubleshooting - is a more in-depth look at solutions, covering import behavior, managed properties, layering strategies and tips and tricks to get the most out of your CRM solutions.

Chapter 23 – Dynamics Connector – From Zero to Hero, in this chapter, you will learn what some of the considerations are when combining CRM with other members of the Dynamics family, what options are available, how to choose and implement the best option or combination of options, and some helpful resources for reference.

Chapter 24 – Rapid Development Best Practices – is an overview of the strategies of preparation, planning, execution and delivery of customizations in an efficient and effective way that meets the needs of the client without reinventing the wheel.

Chapter 25 – Community Resources – is a plethora, a veritable cornucopia, of resources from the global community of user groups, users, MVPs, Microsofties, social media masters and blogs that can help you maximize your CRM skills and guide you to the answers you seek.

 

As you can see, its a lot of information for one book. We hope you enjoy! http://www.crmfieldguide.com/

 

 

CRM 2011 Rollup 11 now available

The Microsoft Dynamics CRM Sustained Engineering (SE) team have been hard at work to get the UR11 release to us all on October 12 2012.

You can find the related Rollup 10 items here

Rollup 11 Build Number: 05.00.9690.2835

Dynamics CRM in the Field has a great post on this subject already including a podcast, along with a lot of other excellent articles, bookmark the site now. Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 11. http://blogs.msdn.com/b/crminthefield/archive/2012/10/05/podcast-and-overview-microsoft-dynamics-crm-2011-update-rollup-11.aspx

The CRM Team Blog also has a brief overview http://blogs.msdn.com/b/crm/archive/2012/10/11/update-rollup-11-for-microsoft-dynamics-crm-2011.aspx

You can find complete CRM download links here on the CRM Wiki http://social.technet.microsoft.com/wiki/contents/articles/2550.microsoft-dynamics-crm-2011-resources-en-us.aspx

Support with CRM 2011, Windows 8, IE 10 and Office 2013

For those of you lucky enough to play with CRM 2011, Windows 8, IE 10 and Office 2013, you should check out these KB articles published on the 16th of Aug 2012.

 

Support with Microsoft Dynamics CRM 2011 and Internet Explorer 10 http://support.microsoft.com/kb/2743941

Support with Microsoft Dynamics CRM 2011 and Microsoft Office 2013 http://support.microsoft.com/kb/2744957

Support with Microsoft Dynamics CRM 2011 and Windows 8 http://support.microsoft.com/kb/2744954