Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Export workflow phases from one environment and import to another environment in SharePoint using CSOM

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 405
    Comment on it

    Workflow phases represents collection of Stages to represent project life cycle.

    Example of phases are :

    1. Create- Project information is captured in this phase.
    2. Select- A subset of projects are selected in this phase.
    3. Plan- An execution plan will be detailed out
    4. Manage - Execution are monitored
    5. Measure- Workflow is finished.

    For creating Workflow Phases using CSOM, there is a class in CSOM is PhaseCreationInformation.

    Exporting: projectContext associated with exporting environment

    //creating custom Phase class to store phase details
    public class CPhase
    {
    	public string Description { get; set; }
    	public Guid Id { get; set; }
    	public string Name { get; set; }
    }
    	
    //Workflow Phases loading...
    projectContext.Load(projectContext.Phases);
    projectContext.ExecuteQuery();
    
    List<CPhase> lstPhase = new List<CPhase>();  //creating list to store to all phases
    
    foreach (Phase phase in projectContext.Phases)
    {
    	CPhase passedPhase = new CPhase();
    	passedPhase.Description = phase.Description;
    	passedPhase.Id = phase.Id;
    	passedPhase.Name = phase.Name;
    
    	lstPhase.Add(passedPhase);   //Adding phase details to list
    }

     

    Importing: projectContext associated with importing environment

    // Loading workflow phases from importing environment
    projectContext.Load(projectContext.Phases);
    projectContext.ExecuteQuery();
    
    //Importing workflow phases to importing environment
    Dictionary<string, Microsoft.ProjectServer.Client.Phase> cachedPhases = new Dictionary<string, Microsoft.ProjectServer.Client.Phase>();  //creating Dictionary to check existing phase
    foreach (Microsoft.ProjectServer.Client.Phase phase in projectContext.Phases)
    {
    	cachedPhases.Add(phase.Name, phase);
    }
    
    Microsoft.ProjectServer.Client.PhaseCreationInformation phaseInfo = null;
    for (int ip = 0; ip <  lstPhase.Count; ip++)
    {
    	try
    	{
    		if (cachedPhases.ContainsKey(Convert.ToString(lstPhase[ip].Name)))
    		{
    			// Phase already exists
    		}
    		else
    		{
    			#region Phase Creation
    			phaseInfo = new Microsoft.ProjectServer.Client.PhaseCreationInformation();
    
    			phaseInfo.Description = Convert.ToString(lstPhase[ip].Description);
    			phaseInfo.Id = new Guid(lstPhase[ip].Id.ToString());
    			phaseInfo.Name = Convert.ToString(lstPhase[ip].Name);
    
    			projectContext.Phases.Add(phaseInfo);
    			projectContext.Phases.Update();
    			projectContext.ExecuteQuery();
    			#endregion
    		}
    	}
    	catch (Exception ex)
    	{
    	  //log exception
    	}
    }

    Hope this code will help you. Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: