CRM 2011 – Transactions and Sharepoint Online

I have previously blogged about using authentication with sharepoint online and I am at it again.

To summarise the blog above you basically have to login to Sharepoint online before you can create the folders and this involves logging on to Office365.  The code checks to see if there any cookies which would have been created if you had logged on and if there aren’t any it logs on and creates those cookies (if I remember correctly).

This caused me some problems when trying to use this code within a CRM plugin.  Firstly I was getting problems because some of my code was a USING statement, I have a couple of good blogs, web pages below.

The main reason this doesn’t work in a plugin is because I think it creates another transaction and this breaks the plugin transaction.

I’m not totally sure about this transaction below but it’s what I think is happening.

I think CRM plugins are based around WCF which is a transactional and my understanding of this is you can’t have a transaction within a transaction.

I had written some code which creates some sharepoint folders based on the document locations records, basically when a project record was being created I wanted to create the sharepoint folder and some other folders within that folder.

I tested the code working from my machine and manually created a an IOrganizationService and getting/retrieving and creating CRM entities etc.  This code also worked and created the sharepoint folders.


when I then put this into a plugin I was getting transaction errors, this was difficult to debug but when I tried to connect to Sharepoint online it crashed out with a transaction error.

To get round this I decided to put the code into a webservice and call that from my plugin and this finally worked.

I could be wrong about transactions and there could be a better way to do this but I’m just happy I got the thing working