Apply changes to cloned items immedialtley using Sitecore Workflow

Intoduction
Sitecore Cloning items is new feature in 6.4 version, it give the ability to reuse same item content in different places in your site, clone item is an actual item that points to another item called origin, and hold the same field's data as the origin.
For more information on clone items, read this document.

The Problem
Creating new version of origin item, will push a UI notification  for user to accept the new change on every cloned item, this could be time wasting for some people if they want these changes to be reflected immediately.



The Solution
Using Sitecore workflow actions, we can enforce origin item new version changes to be reflected on all clone items.

Note: You should notice in code snippets below that states IDs and Commands ID are hard coded here to use Sitecore Sample Workflow, if you plan to use your own workflow, you will need to change these IDs as fit.
 
1- Origin item template should use Sitecore sample workflow.
2- We will create a custom workflow action for 'Awaiting Approval' and 'Approved' states , which will reflect origin new version change on all clone items.
Add the following class to your solution:

[Code Snippet 0]
Loading ....


Code Explanation 
When content editor create new version of origin item, the new version will be in 'Draft' state, then content editor submit new version changes to be approved, here where our code will do the job!.
First we check that current item is not clone item, because we only need to process origin items, Then we get all clone items that use this origin item.
Loading ....

then we check to see if these clone items have notification that require user acceptance (New version of original item), and accept it by code, this will create new version of clone item that hold the new changes.
Loading ....


Now we need new versions of all clone items to be submitted to next state ('Awaiting Approval'), so we get the new version of each clone item, and execute the 'Submit' command.
Loading ....

Now when origin item version is approved, we need to approve clone items new versions.
Loading ....


3- Create action item named 'Reflect on cloned Items' under both states, 'Awaiting Approval' and 'Approved' states items, and fill 'Type String' field with your 'Class Name, Assemly Name'.



Feel free to ask any question!.

Popular posts from this blog

Integrating Lucene.Net.Contrib.Spatial with Sitecore Search API (Geo-Spatial Search)

Caching Rendering HTML when conditional rules are applied

Sitecore Spatial/Geo Location Search Module