Partager via


Workflow.CreateWorkflowStage Method

Creates a workflow stage.

Namespace:  [Workflow Web service]
Service reference: http://ServerName:32843/[Project Service Application GUID]/PSI/Workflow.svc
Web service reference: http://ServerName/ProjectServerName/_vti_bin/PSI/Workflow.asmx?wsdl

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Workflow/CreateWorkflowStage", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Workflow/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Workflow/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub CreateWorkflowStage ( _
    workflowDS As WorkflowDataSet _
)
'Usage
Dim instance As Workflow
Dim workflowDS As WorkflowDataSet

instance.CreateWorkflowStage(workflowDS)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Workflow/CreateWorkflowStage", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Workflow/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Workflow/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void CreateWorkflowStage(
    WorkflowDataSet workflowDS
)

Parameters

Remarks

The WorkflowDataSet.WorkflowStageRow in the WorkflowDataSet.WorkflowStageDataTable contains the phase information.

Project Server Permissions

Permission

Description

ManageWorkflow

Allows the user to manage workflows. Global permission.

Examples

The example uses the SvcWorkflow namespace in the ProjectServerServices.dll proxy assembly. The ConfigClientEndpoints method uses an app.config file for setting the WCF binding, behavior, and endpoint. For information about creating a PSI proxy assembly and an app.config file, see Prerequisites for WCF-Based Code Samples.

The CreateWorkflowStage method is used to create a new stage, Test Stage 5, in the Create phase. After the stage is created, the dataset workflowDS is again written to NewWorkflowStageInfo.xml. Following is a snapshot of the xml file.

<?xml version="1.0" standalone="yes"?>
<WorkflowDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/WorkflowDataSet/">
<WorkflowPhase>
<PHASE_UID>d8bc257b-c2ec-4186-8a5b-44b5b7f21d82</PHASE_UID>
<PHASE_NAME>Create</PHASE_NAME>
<PHASE_DESCRIPTION>Project information is captured in this phase</PHASE_DESCRIPTION>
</WorkflowPhase>
<WorkflowStage>
<STAGE_UID>460f6b0c-1216-46b7-a119-053c32b10d38</STAGE_UID>
<STAGE_NAME>Test Stage 5</STAGE_NAME>
<PHASE_UID>d8bc257b-c2ec-4186-8a5b-44b5b7f21d82</PHASE_UID>
<PHASE_NAME>Create</PHASE_NAME>
<STAGE_DESCRIPTION>Adding a test stage row</STAGE_DESCRIPTION>
<CHECKIN_REQUIRED>false</CHECKIN_REQUIRED>
<STATUS_PDP_UID>a7aa1c62-9577-447c-823e-bdb161f9000d</STATUS_PDP_UID>
</WorkflowStage>

Following is the complete sample code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ServiceModel;

namespace Microsoft.SDK.Project.Samples.WorkFlowTest
{
    class WorkFlowProject
    {
        private static SvcWorkflow.WorkflowClient workFlowClient;
        private const string WORK_ENDPOINT = "basicHttp_Workflow";
        private const string OUTPUT_FILES = @"C:\Projects\Samples\Output\";
        private static string outFilePathWorkFlowStageList;
        private static string outFilePathNewWorkFlowStage;
        private static string outFilePathStageInfo;
        private static string outFilePathUpdatedStage;

        static void Main(string[] args)
        {
            // Configure client endpoints.
            ConfigClientEndpoints(WORK_ENDPOINT);

            Guid[] workFlowID = new Guid[1];
            workFlowID[0] = new Guid("e663d9dc-f78d-4a4e-ac21-b28d22865f58");

            // If output directory does not exist, create it.
            if (!Directory.Exists(OUTPUT_FILES))
            {
                Directory.CreateDirectory(OUTPUT_FILES);
            }

            outFilePathWorkFlowStageList = OUTPUT_FILES + "WorkFlowStageList.xml";
            outFilePathNewWorkFlowStage = OUTPUT_FILES + "NewWorkflowStageInfo.xml";
            outFilePathStageInfo = OUTPUT_FILES + "StageInfo.xml";
            outFilePathUpdatedStage = OUTPUT_FILES + "UpdatedStage.xml";

            // Create a workflow dataset.
            SvcWorkflow.WorkflowDataSet workFlowDS = new SvcWorkflow.WorkflowDataSet();

            // List the workflow stages.
            workFlowDS = ListWorkflowStages(workFlowDS);

            // Create a new workflow stage.
            CreateWorkflowStageTest(workFlowDS);

            // Get workflow stage properties for a given stage.
            GetStageInfo();
        }
                
        // Read and display the properties of a stage, given the stage GUID.
        private static void GetStageInfo()
        {
            SvcWorkflow.WorkflowDataSet stageInfoDS = new SvcWorkflow.WorkflowDataSet();
            string stageName = "TestStage10";
            
            Guid stageGuid1 = new Guid("a8a158d1-a9b9-41d7-a676-d199118221c7");
            stageInfoDS = workFlowClient.ReadWorkflowStage(stageGuid1);

            Console.WriteLine("\nSee XML output of the WorkFlowDataSet at {0}",
               outFilePathStageInfo);

            // Update the stage name.
            UpdateStage(stageInfoDS, stageName, stageGuid1);

            // Get the updated stage info.
            stageInfoDS = workFlowClient.ReadWorkflowStage(stageGuid1);
            stageInfoDS.WriteXml(outFilePathStageInfo);
            Console.ReadKey();
        }
               
        // Update the stage name.
        private static void UpdateStage(SvcWorkflow.WorkflowDataSet stageInfoDS, string stageName, Guid stageGuid1)
        {
            SvcWorkflow.WorkflowDataSet.WorkflowStageRow sRow;
            sRow = stageInfoDS.WorkflowStage.FindBySTAGE_UID(stageGuid1);
            sRow.STAGE_NAME = stageName;
            Console.WriteLine("Updating the stage name........");

            workFlowClient.UpdateWorkflowStage(stageInfoDS);

            // Write the updated stage info to an xml file.
            stageInfoDS.WriteXml(outFilePathUpdatedStage);
            Console.WriteLine("Stage name updated!");
            Console.WriteLine("\nSee XML output of the Updated WorkFlowDataSet at {0}",
            outFilePathUpdatedStage);
        }

        // Create a workflow stage.
        private static void CreateWorkflowStageTest(SvcWorkflow.WorkflowDataSet workFlowDS)
        {
            // GUID of the Create phase.
            Guid phaseGuid = new Guid("d8bc257b-c2ec-4186-8a5b-44b5b7f21d82 ");  

            Guid statusPDPId = new Guid("A7AA1C62-9577-447C-823E-BDB161F9000D");
            Guid pdp_uid = new Guid("659FF164-1297-4B64-B813-489566774E27");
            Guid stageUid = Guid.NewGuid();
                       
            // Create a workflow stage row.
            SvcWorkflow.WorkflowDataSet.WorkflowStageRow workflowstageRow = 
                workFlowDS.WorkflowStage.NewWorkflowStageRow();
            workflowstageRow.STAGE_NAME = "Test Stage 5";
            workflowstageRow.STAGE_DESCRIPTION = "Adding a test stage row";
            workflowstageRow.PHASE_NAME = "Create";
            workflowstageRow.PHASE_UID = phaseGuid;
            workflowstageRow.CHECKIN_REQUIRED = false;
            workflowstageRow.STAGE_UID = stageUid;
            workflowstageRow.STATUS_PDP_UID = statusPDPId;
            workFlowDS.WorkflowStage.AddWorkflowStageRow(workflowstageRow);

            // Add a project details page for the stage that was created previously.
            SvcWorkflow.WorkflowDataSet.WorkflowStagePDPsRow pdpRow = 
                workFlowDS.WorkflowStagePDPs.NewWorkflowStagePDPsRow();
            pdpRow.STAGE_UID = stageUid;
            pdpRow.PDP_UID = pdp_uid;
            pdpRow.PDP_NAME = "Project Information";
            pdpRow.PDP_POSITION = 0;
            pdpRow.PDP_ID = 4;
            pdpRow.PDP_REQUIRES_ATTENTION = false;
            workFlowDS.WorkflowStagePDPs.AddWorkflowStagePDPsRow(pdpRow);
        
            // Create the stage.
            workFlowClient.CreateWorkflowStage(workFlowDS);
            
            // Write the dataset with the new stage to an xml file.
            workFlowDS.WriteXml(outFilePathNewWorkFlowStage);
            Console.WriteLine("\nSee XML output of the WorkFlowDataSet at {0}",
               outFilePathNewWorkFlowStage);
        }

        // List the workflow stages in the dataset.
        private static SvcWorkflow.WorkflowDataSet ListWorkflowStages(SvcWorkflow.WorkflowDataSet workFlowDS)
        {
            workFlowDS = workFlowClient.ReadWorkflowStageList();
            workFlowDS.WriteXml(outFilePathWorkFlowStageList);

            Console.WriteLine("\nSee XML output of the WorkFlowDataSet at {0}",
               outFilePathWorkFlowStageList);
            return workFlowDS;
        }

        // Configure the custom field client endpoints.
        public static void ConfigClientEndpoints(string endpt)
        {
             workFlowClient = new SvcWorkflow.WorkflowClient(endpt);
           
        }
    }
}

See Also

Reference

Workflow Class

Workflow Members

Workflow Web Service