Simple CRM and SharePoint integration example

During the Swedish SharePoint and Exchange Forum 2006 held just outside Stockholm on Rosenön this spring, I showed how to make a simple integration of MS CRM and MS SharePoint 2003.

Both technologies are very versatile and are easily integrated with other software, mainly due to the helpful webservices that are available.

The integration I created was to automatically create a workspace when a new account was created. The following steps describe how this was made possible:

1. Create a site in SharePoint that will contain all subsites.
2. Create a new attribute in CRM, nvarchar 255 that will contain the SharePoint site URL.
3. Create an IFrame in CRM. Modify the onload JavaScript in CRM to set the src of the IFrame to the SharePoint site URL (if it is not null).
4. Create a dll that creates the SharePoint site and return the new sites URL and can be called on by a CRM workflow.
5. Modify the workflow.config to add the functionality to the workflow manager.
6. Create the workflow triggered by Create on account that creates the site and return the URL. Set the new SharePoint-site-url attribute to the return value of the function.

This integration is good, and it is also possible to create a more enhanced handling by using the PreCreate Callout instead of using the workflow. However, the workflow-addon created can be constructed to be quite generic and can hence be used for other purposes as well, (for instance creating a SharePoint site for each Opportunity).

I will base the SharePoint-site-name on the accountname attribute which is not guaranteed to be unique. In this example I will not go through how to make a duplet checking program, which should also be created, if the sites should be based on accountname. The sitename could also be based on the account GUID which is guaranteed to be unique.

I will now go through each of the six points in more detail:
1 . Create a SharePoint site that will contain all subsites
Just use the standard SharePoint interface, choose create from the top menu and then select site, almost at the bottom of the list, no specific template is needed. Note the url to the newly created site.
2. Create a new attribute for the SharePoint site url
In CRM, choose settings, customizations, customize entitys, account, attributes, create. Create a new attribute called for instance “new_spsiteurl” as nvarchar and length 255 (255 should be enough for anybody :).
3. Create an IFrame in CRM
Now choose forms and views in CRM. Choose form. You should now see the editable version of the account form. Click “New Tab” in the right hand menu. Name the new tab “SP Site” or something appropriate. The tab should now be visible.

Select the “SP Site” tab and then choose “Create section” from the right hand menu. Call it something nice. Also select to not show the name of the section.

In the new section, select “Add field”. Choose the newly created attribute, “new_spsiteurl”. Check the checkbox for read-only. Click OK.

Now choose “Create IFrame” from the right hand menu. Create an IFrame in the section created above. Check the checkbox in formatting that makes it fill the form. Call the IFrame something like “IFRAME_spframe”. Click ok to create.

Click the “Form Properties” in the right hand menu at the bottom. Edit the onLoad script. Put in the following script:

If (crmForm.all.new_spsiteurl.DataValue != null)
{
crmForm.all.IFRAME_spframe.src = crmForm.all.new_spsiteurl.DataValue;
}

Close the dialogs. Click save and close on all forms. When you are back to the main CRM-window, select account in the entities list and click “publish”.

4. Create the workflow addon dll
Open Visual Studio 2003 (it will work with VS 2005 as well, however, if you want to do this with callouts, you will have to follow the instruction concerning callout development in VS 2005 that I have blogged about earlier, with reference to Arash blog).

Create a new basic C# project with a simple class-file. Name the project something like “WFAddons”. Rename the cs-file something like “WFAddons”, make sure that the code is coherent with the naming of the file to avoid any confusions.

Make sure you have a reference to the SharePoint-dll.

With all the code to create the SharePointsite, the file should look something like this:

using System;
using Microsoft.SharePoint;

namespace WFAddons
{
public class WFAddons
{

public string CreateWorkSpace(string accountname)
{
SPSite siteCollection = new SPSite(“http://localhost/sites/konton”);
SPWebCollection subSites = siteCollection.AllWebs;

SPWeb mySite = subSites.Add(accountname);
mySite.Title = accountname;
mySite.Name = accountname;
mySite.Update();
return mySite.Url;
}
}
}

In the row: SPSite siteCollection = new SPSite(“http://localhost/sites/konton”);
Modify the url to match the site created in step 1.

Now set the output directory to the CRM-assembly folder. This is usually found here:
c:Program FilesMicrosoft CRMServerbinassembly but is dependant on the CRM-installation.

Compile the project.
5. Modify workflow.config
In the folder: c:Program FilesMicrosoft CRMServerbinassembly, open the file workflow.config and before the end tags
(
</methods>
</workflow.config>
)

add the following:

<method name=”Create workspace”
assembly=”WFAddons.dll”
typename=”WFAddons.WFAddons”
methodname=”CreateWorkSpace”
group=”SharePoint functions”>
<parameter name=”accountname” datatype=”string”/>
<result datatype=”string”/>
</method>

Make sure the settings corresponds with how you have compiled the workflow-addon-dll. The parameters are describes here:
Assembly – this is the name of the file found in the assembly directory.
Typename – this is the namespace followed by a dot and then the classname.
Methodname – this is the name of the method when working with it in Workflow Manager.
Group – Methods in Workflow Manager are Grouped. This is the group name.
Parameter name – this is the name that will be displayed in workflow manager for the first parameter. If you want to add more parameters just add them bellow. The name of the parameter does not have to be the same as in the code. However, the datatype must correspond.
Result – this is the data type of the return value.

Also, on the top line, in the top tag, add the following: allowunsignedassemblies=”true” to allow unsigned assemblies to be executed by the workflow engine.

Before saving this file, shut down the process called: Microsoft CRM Workflow Service. Then save and start the process again.
6. Create the workflow
Now, all you have to do is create the workflow that will run all this and tie everything together. Open the workflow manager, select account, and create a new workflow that will be triggered on create. In the editor, select “Insert Action” and choose “Call assembly” select the group name (the same set in workflow.config above), and the select the method name. In the new dialog window, double-click the parameter (the name set in workflow.config) and choose dynamic value and select the entity Account and choose the attribute accountname. In the main action dialog, a you can now see this mapping. Enter an action name, like “create workspace”. Click “Save”.

You should now see the main workflow editor window. Press “Insert Action” on the left hand menu and choose “Update entity”. A new dialog is show. Make sure the entity is marked as “Account”, select the field “new_spsiteurl”, choose “=” and not “+=”, and then click the button to the far right on the same row. A new dialog is shown, choose dynamic value and in the dropdown called entity you should be able to select “create workspace”, the name of the action that created the site. Close all the windows with “OK”, “OK”, “Save”. You should now see the list of all account workflows. Select your new workflow and hit activate.

Now everything should be working as long as the uses running it all has sufficient rights. Try it out by creating an account, closing it, waiting 5 seconds (to let the workflow finish) and then open the account again. Go to the workspacetab where you should now see the SharePoint site that you created.

If you have problems, check the workflow monitor to see if the workflow ran properly or if it has stalled.

Please let me know of any problems or errors in this description. You are free to use my code, and description as long as you give me credit for it and link to my blog.

Please note that this example was made to show how it can be done. Please use it as a suggestion on this type of integration.

Gustaf Westerlund
HumanData AB
Markörgatan 4
136 44 HANINGE
Sweden
http://www.humandata.se

Tel:

Mobil: 0730-843 505

E-post: gustaf@humandata.se

SharePoint and Access

This post will concern SharePoint for once in a while!

As most of you know, it is possible to link SharePoint lists to excel, however, it is also possible to link SharePoint lists as tables in Access. This is very usefull since you can then create more advanced views using complex SQL. Data can also be linked with data from other sources, if needed. There should also be some ODBC driver that could be used to fetch data from a SharePoint list, however, I havn’t seen one. If I do, I will let you know.

How to link a SharePoint list into Access as a table:
1. Make a new view in SharePoint with all columns and all rows. Call it something nice like “everything”.
2. In access, choose the file menu and then choose “Get external data” (I am using the swedish version of access, so excuse my translation) and then choose “Link tables”. In the dialog that opens, you can choose SharePoint list from the filetype dropdown. Then enter the url for the site, not the list. You will then be prompted for which list you want to use and so on and so forth. When done, you will have one maybe more linked tables in Access which will work just as any other tables in access.

Happy SQL:ing!

Gustaf Westerlund
CRM and SharePoint Consultant

Humandata AB
www.humandata.se

Developing with VS 2005

Extending MS CRM 3.0 is normally done using Visual Studio 2003 and this is also the only supported development environment. However, it is possible to develop using VS 2005 as well. Some things have to be considered.

.NET 2.0 will work fine for external web applications using the CRM Webservice (not very strange since the webservice is generic)

.NET 2.0 will probably also work fine when developing workflow dll:s, but it is not supported. At least it worked when I tested Hello World! 🙂

.NET 2.0 will not work when developing callouts. However, there is a great description of how to develop these in VS 2005 anyway but for .NET 1.1. Beware that you cannot use specific .NET 2.0 functionality.

Here is the site: http://blogs.msdn.com/arash/archive/2006/08/25/719626.aspx

A good thing with this is that the standard TDT can be used when developing customizations. I am no licensing expert, so make sure it’s within your licensing agreement.

Gustaf Westerlund CRM and SharePoint Consultant

Humandata AB
www.humandata.se

Odd SQL Reporting Services Error…

I was working with a custom report today and I had a very strange error which I have noticed that several others also seem to have, both with SQL Reporting Services and other .NET applications. The report I was making worked fine, but when I tried to deploy it to the site, I got the following error:

“Length cannot be less than zero.”

When I dubbel-clicked it in VS2003 (yes, I am still using it), the sourcefile of my DataSource was shown, and there was nothing wrong there…

Well, I tried lots of different things, restarting, trying to deploy to another server but the error was still the same and I could see the report was working fine i Preview mode.

Well, after a while I got fed up with it, and just tried to install the rdl manually on the reportserver (using the update function, in the properties tab of the report). It worked!

Hence, there seems to be some error in the deployment of reports in SQL Reporting Services. If you get this error, try to bypass it, your report might not be the problem after all.

Anyone reading this that knows why the deployment didn’t work? I’d like to know!

Gustaf Westerlund
CRM and SharePoint Consultant

Humandata AB
www.humandata.se

Web and Outlook mixup

As some of you might have noticed, if you have the Outlook desktop client installed and Outlook open, and then open CRM using IE, you will loose some web-specifics like the “Settings” menu and other addons specified in the sitemap or isv.config.xml as “web”.

This is due to the fact that these files are downloaded to the client by IE when Outlook is started and these are then cached by IE. When the same URL is opened, IE recognizes these files, and does not download any new files, hence you get the Outlook-client specific.´

How to solve this? IE bases its caching on the url so you just have to install the crm-outlook-client to one url and use the webclient for the other. Note that you can even use the IP adress as one of the url:s, since IE doesn’t resolve the name when checking for cache-hits.

Gustaf Westerlund
CRM and SharePoint Consultant

Humandata AB
www.humandata.se