A colleague of mine asked me the other day if it was possible for him to access his Microsoft Dynamics CRM data directly from inside SharePoint by using the OData service that CRM exposes. Of course, this is possible the question is how to go around doing it. He was looking for a no-code solution that would work in an online scenario with SharePoint online and CRM online. His initial idea was to use SharePoint Business Connectivity Services, which from the 2013 version of SharePoint support connecting to OData sources. This is a very valid approach, but since I was looking into LightSwitch earlier this week, I wanted to see if LightSwitch could be used a as solution too.
Of course using LightSwitch is not a exactly a no-code solution, but it’s pretty close, and in addition we get the option to surface the CRM data outside of SharePoint too, for instance in a mobile app if we want to.
Connecting LightSwitch to CRM data services
Connecting a LightSwitch project to an OData source is a walk in the park. Just add a new data source of the type OData Service. In the endpoint use:
http://[server]/[organization]/XRMServices/2011/OrganizationData.svc
You have to exchange the [server] and [organization] with your server and organization, in my test I used a CRM 2013 instance (hosted in windows azure).
If your users have access to CRM and you only want to give them access to data that they already can see, you can use windows authentication.
In my proof-of-concept, it was a requirement that we connected to the data with a service account, so I selected “Other” and typed in domain\username and password.
Update, connecting to CRM online
Unfortunately, at the moment I haven’t found way to connect to CRM online’s OData endpoint, but I will post an update when I find a solution, to the microsoft live id signon problems.
When you press next, Visual Studio will connect to the OData endpoint and download the metadata information, since CRM have quite a lot of data exposed via OData, this might take a little while. Afterwards you can select the entries you want to work with.
I just selected the “AccountSet” and left the data source name
When you click “Finish” you will be presented with a list of warnings of data types that isn’t support. So far, I have not noticed any problems with just ignoring the warning.
Creating Screens
Once the data is accessible to your LightSwitch Server project it is time to create some Screens, to enable browsing of the data.
Adding screens are not any different from adding screens to any other LightSwitch project, so I will not go into details with that here. I just added a BrowseAccountSet, AddEditAccounSet and ViewAccountSet. In each screen you can, select which fields you want the user to be able to modify, as the account entity per default have quite a huge number of fields, I left pretty much all of it unmodified and it still worked except for one detail with the AccountID field.
The AccountID is the only per data model required field, but the screen designer maps it to a text field that the user have to fill out, since the AccountID must be a unique guid, this is not very user friendly. What I did was to change the ControlType of the field to Text (so it can’t be changed). In the data-model designer, I switched to the HTMLClient view and in the created method, I added the following code.
[js]
/// <reference path="../GeneratedArtifacts/viewModel.js" />
myapp.AccountSet.created = function (entity) {
// Write code here.
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
};
function guid() {
return s4() + s4() + ‘-‘ + s4() + ‘-‘ + s4() + ‘-‘ +
s4() + ‘-‘ + s4() + s4() + s4();
}
entity.AccountId = guid();
};
[/js]
This code just fills the AccountId with a randomly generated Guid, so that the client side validation doesn’t complain about the AccountId being empty.
With this little adjustment, I was able to create new CRM accounts directly in from my LightSwitch application and browse my existing accounts.
Publishing the Application to Windows Azure/SharePoint Site
The final step was to publish the application to either Windows Azure or SharePoint. Publishing the application to SharePoint require you to enable SharePoint for the project.
With SharePoint enabled you just right-click the BaseProject and click Publish.
Then you will get the publishing wizard. The easiest way to get up and running is to select SharePoint AutoHosting, that way SharePoint will handle all provision of your App when it is installed inside of SharePoint, and since data doesn’t live in the LightSwitch application, it should be sufficient for most uses.
It is not support from the GUI to have the same application hosted both as a SharePoint application and as a stand-alone application in Windows Azure. But if you remove the SharePoint integration or make a separate project for your Azure Hosting, you can from the publishing wizard under Application type chose “Complete Application” and in the next step “Application Server Configuration” select “Windows Azure” and from here you can deploy it directly to a windows azure website that you must have created beforehand.
One thing I noticed with the windows azure hosting is that if you want to be able to browse the client on your https://[your-domain].azurewebsites.net without adding /HTMLClient, you have to add a defaultDocument value for default.aspx to the web.config in the server project. So it looks something like.
Finally, here are a few screenshots of the very standard looking LightSwitch app, inside of SharePoint.
The app installed inside SharePoint
Account Details
Edit/New Account
Categories: SharePoint Software
I get the following error : /XRMServices/2011/OrganizationData.svc/ does not appear to be a valid OData service.
same issue as suvarna
I will see if something is wrong with my sample, and update if necessary.
I have the same issue, trying to connect to CRM 2013 online.
When I type the exact same service uri into my browser, I can an xml response that looks about right, but in VS2013 lightswitch no joy 🙁
Hi Niel, I was apparently a bit quick when I wrote the article. Unfortunately it doesn’t work with CRM online 2013. The server I was connecting to was a CRM (on prem) hosted in windows azure. And not a real CRM online.
I’m working on a solution, for CRM Online, but that is a little more involved atm.
Hey Simon.
Is there in the meantime a way to do this with CRM 2013 Online?
Hey!
Did you find a solution for Dynamics CRM 2013 Online ?
Sorry guys for not getting back to you with a solution that works with Dynamics CRM 2013 online.
I do have a solution, it’s just kinda involved to get working, so I have been holding it back in hopes that Microsoft would release a real integrated solution like the one they have for SharePoint. But as they seems to only be focused on LightSwitch technology together with SharePoint, maybe I have to post my solution so they can see how they should add support for CRM from LightSwitch too.
Please do or email me if you prefer. I appreciate it very much!
I have posted my guide on how to access CRM online from LightSwitch here: http://wp.sjkp.dk/use-microsoft-dynamics-crm-online-data-in-lightswitch/
Hi Simon, I am currently trying to connect MS CRM 2013 On-Premise with LightSwitch and found that LightSwitch doesn’t supports CRM “Lookup” control. Is there any other alternative/am i missing some steps ?
Hi Sayan,
Unfortunately I haven’t worked with LightSwitch and CRM on a real project, so I haven’t had the chance to test out all the controls, so I can’t really provide you with any valuable information on how to get it working, sorry.
Hi Simon,
I have tried this approach to get the entityimage field value but it doesn’t work. Have you had a chance to load an image using this approach?
Thanks