Thursday, November 12, 2009

Custom Workflow in Project Server 2007 - Part 3

Part 1
Part 2



Step 4 - Create a custom workflow


For More details on WSS workflow check this article .


Open the Sequential Workflow file (PublishingWorkflow.cs) in design mode and add following activites -
  1. OnWorkFlowActivated activity

  2. Sequence activity : Rename this activity as 'PendingNotfications' and add following child activites -
    • SendEmail - Rename this activity as 'SendRequestForApproval'

    • SendEmail - Rename this activity as 'SendPendingNoticeToPublisher'

  3. While activity – Rename this activity as 'WhileWaitingForApproval' and add following child activities.
    • OnWorkflowItemChanged activity

  4. IfElse activity
    • First branch : Add following child activities -
      • InvokeWebService activity – Rename this activity as 'EPMProjects'.Add the web reference as -
        Reference name – psiProjects ,
        URL = http://server/pwa/_vti_bin/psi/project.asmx

      • SendEmail activities - Rename this activity as 'SendApprovalEmail'

    • Second Branch : Add following child activities -
      • SendEmail activities - Rename this activity as 'SendRejectedEmail'


The final design view should look like this -


The red exclamation icon in the upper-right corner of activities icon indicates that a required property must be set.Clicking the icon displays the list.

Now open the PublishingWorkflow.cs file in code view and add following using statement & class members -

  • using EPMWF.psiProjects; //NameSpace.Psi Web Refrence Name

  • public Guid workflowId = default(System.Guid);
    public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();


Set Activity Properties
Open the workflow file in design view and set the required properties of each activity as mentioned below -
  • Activity - OnWorkFlowActivated1
    • Correlation Token = publishWorkflowToken
      Correlation Token\OwnerActivityName = PublishingWorkflow
      WorkflowProperties\Name = PublishingWorkflow
      WorkflowProperties\Path = workflowProperties

    • Invoked = OnWorkflowActivated1_Invoked
      After You Enter method name here, VS.net will jump to code with a method signature created.

  • Activity = SendRequestForApproval
    • Correlation Token = publishWorkflowToken
      Correlation Token\OwnerActivityName = PublishingWorkflow

    • Body - select the Body row and click the ellipsis.Click Bind a New member field.enter name = m_MailToBody ; Select Create field option, click Ok .Verify Name and Path
      Body\Name = PublishingWorkflow
      Body\Path = m_MailToBody

    • Headers - Create field in the same as done for Body.Name =m_MailToHeader.The Headers property is a hash where the Subject and To fields can be specified
      Headers\Name = PublishingWorkflow
      Headers\Path = m_MailToHeader

    • MethodInvoking = SendRequestsForApproval_Invoking
      After You Enter method name here, VS.net will jump to code with a method signature created.

  • Activity = SendPendingNoticeToPublisher
    • Correlation Token = publishWorkflowToken
      Correlation Token\OwnerActivityName = PublishingWorkflow
      Body\Name = PublishingWorkflow
      Body\Path = m_MailToBody
      Headers\Name = PublishingWorkflow
      Headers\Path = = m_MailToHeader
      MethodInvoking = SendPendingApproval_Invoking



  • Activity = WhileWaitingForApproval
    • Condition = Code Condition
    • Condition = WhileWaitingForApproval_ Condition
      After You Enter method name here, VS.net will jump to code with a method signature created.


  • Activity = OnWorkflowItemChanged
    • Correlation Token = publishWorkflowToken
      Correlation Token\OwnerActivityName = PublishingWorkflow


  • Activity = ifElseBranchActivity1
    • Condition =Code Condition
      Condition = IfApproved_Condition


  • Activity = EPMProjects
    • MethodName =QueuePublish

    • Create fields for following properties in the same way as in Body
      ReturnValue = m_PublishResult
      JobUid = m_PublishJobGuid
      ProjectUid = m_ProjectGuid
      WssUrl = m_PublishWssUrl

    • FullPublish=True

    • Invoking =PsiQueuePublish_Invoking
      VS.net will jump to code with a method signature created.


  • Activity = SendApprovalEmail
    • Correlation Token = publishWorkflowToken
      Correlation Token\OwnerActivityName = PublishingWorkflow
      Body\Name = PublishingWorkflow
      Body\Path = m_MailToBody
      Headers\Name = PublishingWorkflow
      Headers\Path = = m_MailToHeader
      MethodInvoking = SendApproval_Invoking



  • Activity = SendRejectedEmail

    • Correlation Token = publishWorkflowToken
      Correlation Token\OwnerActivityName = PublishingWorkflow
      Body\Name = PublishingWorkflow
      Body\Path = m_MailToBody
      Headers\Name = PublishingWorkflow
      Headers\Path = = m_MailToHeader
      MethodInvoking = SendRejected_Invoking




After setting all these properties Visual studio will automatically create some member declaration & empty method signatures for you. The code file will look like this...


namespace EPMWF
{
public sealed partial class PublishingWorkflow: Microsoft.SharePoint.WorkflowActions.SharePointSequentialWorkflowActivity
{
public PublishingWorkflow()
{
InitializeComponent();
}

public Guid workflowId = default(System.Guid);
public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();

public String m_MailToBody = default(System.String);
public System.Collections.Specialized.StringDictionary m_MailToHeader = new System.Collections.Specialized.StringDictionary();

private void OnWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e){}

private void SendRequestsForApproval_Invoking(object sender, EventArgs e){}

private void SendPendingApproval_Invoking(object sender, EventArgs e){}

private void WhileWaitingForApproval_Condition(object sender, ConditionalEventArgs e)
{}

private void IfApproved_Condition(object sender, ConditionalEventArgs e){}

public Guid m_ProjectGuid = default(System.Guid);
public ProjectRelationsDataSet m_PublishResult = new EPMWF.psiProjects.ProjectRelationsDataSet();
public Guid m_PublishJobGuid = default(System.Guid);
public String m_PublishWssUrl = default(System.String);

private void PsiQueuePublish_Invoking(object sender, InvokeWebServiceEventArgs e){}

private void SendRejected_Invoking(object sender, EventArgs e){}

private void SendApproval_Invoking(object sender, EventArgs e){}
}
}


Part 4 - Writing Codes for Activities

No comments: