Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 7025

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 2162

Deprecated: Hook imagify_allow_picture_tags_for_webp is deprecated since version 2.2! Use imagify_allow_picture_tags_for_nextgen instead. in /www/collab365_296/public/wp-includes/functions.php on line 5758
How to implement transactional behavior within SharePoint - Collab365
Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Warning: Undefined array key "url" in /www/collab365_296/public/wp-content/plugins/thrive-visual-editor/thrive-dashboard/inc/smart-site/classes/class-tvd-smart-shortcodes.php on line 85

I’ve been working on a “start up” which does product development, trying to implement what SharePoint does not offer in our country regarding no-paper policies.

Most of our operations involve a lot lists and libraries, the usual sharepoint approach did not work for us since it was impossible to undo all previous operations given an unhandled (or handled) exception occurred. So we decided to try a transactional approach.

Let’s do a bit of abstraction on a transactional operation, we find that there are two basic operations: do something and undo that which we did.

Lets be a little more elegant: lets call those two operations Execute() and Undo(). Let’s start then, with a simple interface:

image

With a little bit more on thought on the matter, we can separate transactions on two groups: a single operation or a set of operations. Since we are doing transactions on SharePoint, I propose atomic transactions to have and SPListItem and an SPWeb, and those which are a collection of operations to have additionally a collection of transactions.

The atomic transaction is pretty simple:

image

We have a couple of constructors and a couple of abstract operations to be implemented on the child classes, and the SPListItem and SPWeb objects to work with.

The transaction collection, on the other hand, is a little bit more complex:

image

Yes, there is a Stack object there to store the operations. Let suppose for a moment that you are executing a large batch of operations and something fails. You need to start undoing stuff beginning with the last operation and ending with the first operation. Yes we need a LIFO data structure, and the Stack provides this kind of behavior.

So now that we have our base classes, we can begin writing some transaction implementation for our base Sharepoint operations: create, update and delete.

Since there is NO WAY in this world to recover an Item after doing a SPListItem.Delete(), so instead I’m going to use Recycle(), which allows us to recover stuff from the SharePoint Recycle Bin.

After digging up a little bit how the recycle works we find that after recycling an element we get a Guid which identifies the element on the bin. So our delete command will have a Guid as a field so we can recover the element from the bin in case something fails…

image

The SPUpdate, and SPCreate commands are on the visual studio solution, which can be grabbed from here. The SPCreate is a nice sample of a CommandCollection, so remember to give a look to it.

Happy coding

(Visited 408 times, 1 visits today)

About the author 

Jaime Alberto Jaramillo Zapata

Summit Bundle

Get 200+ hours of Microsoft 365 Training for 27$!

Master Office 365, Power Platform & SharePoint & Teams With 200+ Hours Of Training Videos and 108 Ebooks in the Collab365 Academy. This offer is insane and is only available for a limited period.