Monday, April 15, 2013

How to get minor version in Tridion Workflow 2011 SP1 using Coreservice

If you had worked in Tridion Workflow,
You could have encountered a situation where you need to get the current version of workflow. eg 2.1 and 2.2 using Sample code.
Below is the sample code to retrieve current version of item

Background for Tridion Item Versions:
All Tridion major versions are checked in at as 1.0, 2.0, 3.0 +++++
However, when an item is entered in workflow it can be edited and first it enters with version 1.1 and if some one(eg: approver) modifies is when item is in workflow the version is 1.2 and If approver sends back to author and when author edits this content version would be 1.3 and so on... basically an item entered in workflow when edited will have version X.1, X.2, X.3 ... ++++

For eg: I had a requirement that a content entered inside a workflow when approvers/publishers edit the content. The content should be sent back to author.

Solution 1: You can either write an event system which doesn't let you save and close

So event system checks if component in workflow, then takes current activitydefinition and checks if its Description contains #READONLY# some thing like below

  private bool IsActivityReadOnly(ActivityInstance activity)
        {
            return activity != null && activity.ActivityDefinition.Description.Contains(READ_ONLY_PLACEHOLDER);
        }
And don't let Save and Close

Solution 2:  Convoluted One :)


After Content Creation there is Publish to Preview and Notify US Approver activity which always takes note of current revision of author creation

C# Code Snippet: In Publish to Preview and Notify US Approver
Takes note of versions revision which will give you X of 1.X
       FullVersionInfo creatorVersionInfo = newComp.VersionInfo as FullVersionInfo;
versionNumber = creatorVersionInfo.Revision.Value;


 I would always compare this number after approver approves/ publisher approves. If he/she changed content. In below diagram: After US approver appoves --> content goes to Businnes-Approvers. So before going to Business Approvers. Send to Business-Approvers Review will check version number with above versionNumber. If something in content is changed after  Author sent for for approval then it will send back to author


C# Code Snippet: Send to Business-Approvers Review

ComponentData newComp = CoreServiceClient.Read(GetTcmUri(component.Id, component.LocationInfo.ContextRepository.IdRef,
0), options) as ComponentData;
FullVersionInfo VersionInfo = newComp.VersionInfo as FullVersionInfo;
int version = VersionInfo.Revision.Value;
if (version != versionNumber)
// then use DecisionActivityFinishData to Send Back to Author 
                               else
                                        // then use DecisionActivityFinishData to Assign to Business Approvers Review





No comments:

Post a Comment