Skip to main content

Posts

Showing posts with the label YAWF

Create and Publish Page for Component in Workflow using Core Service

It seems like this use case keeps coming back time and time again. The requirement: when a new Component is in workflow, part of the approval workflow on the Component should be an automatic Page generation (where the Component is placed on the Page) and possibly publishing of the Page for the purpose of previewing the new Component in a Page context. All this while Component is in workflow, so approver can actually see how the Component looks like before approving/rejecting it. The only issue, as described in the previous post, is that it is not possible to add a v0.x Component to a Page, when the Page is in a child Publication. The solution is to do all this programmatically. In the following example, I use the Core Service to create a new Page (with values taken from a Folder metadata, for example) and place the v0.x Component on it. using ( CoreServiceSession coreService = new CoreServiceSession ()) {      if (component.Version < 1)   ...

Workflow GetNextActivityInstance

The following code sample shows how to read the next ActivityInstance in a workflow. Mind you that for this to work, the current Activity has to be finished. Only then a next Activity Instance is created, and can thus be retrieved: /// <summary> /// Get the next ActivityInstance, if there is one. If the current Activity has not finished, there is no next activity. /// </summary> /// <returns></returns> protected ActivityInstance GetNextActivityInstance() {      ActivityInstance activityInstance = CurrentWorkItem.Activity as ActivityInstance ;      ProcessInstance processInstance = activityInstance.Process as ProcessInstance ;      IList < ActivityInstance > activities = new List < ActivityInstance >(processInstance.Activities);      if (activityInstance.Position < activities.Count) { //Position is 1-based          return activi...

Workflow GetNextActivityDefinition

To continue my series of Workflow utility methods, today I'm presenting a way to retrieve the next Activity Definition, relative to the current Activity in the Workflow Process. /// <summary> /// Return the next activity definition, if there is one. /// </summary> /// <returns></returns> protected ActivityDefinition GetNextActivityDefinition() {      ActivityInstance activityInstance = CurrentWorkItem.Activity as ActivityInstance ;      TridionActivityDefinition activityDefinition = activityInstance.ActivityDefinition as TridionActivityDefinition ;      ProcessDefinition processDefinition = activityDefinition.ProcessDefinition;      IList < ActivityDefinition > activityDefinitions = new List < ActivityDefinition >(processDefinition.ActivityDefinitions);      IList < TridionActivityDefinition > nextActivities = null ; ...

Workflow GetLastManualActivityInstance

Sometimes in practice, you need to get the last manual activity of a workflow. This is the last activity that was performed before the current activity and that is not automatic (i.e. was performed by a user). A use case is to retrieve the message that the user completed his manual activity with. /// <summary> /// Return the last manual activity instance from the current process instance /// </summary> /// <returns></returns> protected ActivityInstance GetLastManualActivityInstance() {      ActivityInstance activity = CurrentWorkItem.Activity as ActivityInstance ;      ProcessInstance processInstance = activity.Process as ProcessInstance ;      List < ActivityInstance > activities = new List < ActivityInstance >(processInstance.Activities);      for ( int i = activity.Position - 1; i >= 0; i--) {          Act...

Workflow GetLastActivityInstance

Writing workflows implies sometimes having to navigate back and forth through the different activities. For example for taking the message of the last Activity, or taking the Assignee of the next Activity. This post gives code samples for retrieving the last Activity Instance. This is the previous Activity Instance that was completed before the current one. /// <summary> /// Return the last activity instance from the current process instance /// </summary> /// <returns></returns> protected ActivityInstance GetLastActivityInstance() {     ActivityInstance activity = CurrentWorkItem.Activity as ActivityInstance ;     ProcessInstance processInstance = activity.Process as ProcessInstance ;     IList < ActivityInstance > activities = new List < ActivityInstance >(processInstance.Activities);     for ( int i = activity.Position - 1; i >= 0; i--) {        ...

Workflow FinishActivity

Where you ever annoyed with the ActivityFinish class? Namely, that second parameter nextAssignee of type Trustee  of the constructor? The constructor signature is the following: public ActivityFinish( string message, Trustee nextAssignee, Session session); So what do I pass as nextAssignee? Figuring that out is not easy... Luckily though, you can simply pass null for the assignee and Tridion will then use the user/group that is defined in the Activity Definition (in the Workflow Visio diagram). What if I want to properly assign a nextAssignee? How do I figure out who the next assignee should be? Well, one way I used in the past was to identify the last manual Activity (thus not automatic, because they are performed by the implicit Tridion user as defined in the SDL Tridion Content Manager MMC snap-in / Workflow settings / Automatic Trustee ID ). Then I used this Trustee for the ActivityFinish. Alternatively, as shown by the code-below, I identify the next...