Post on subject restarting your workflow is here, and description of FluentPS can be found here.
First, let's see how do you change Enterprise Project Type of a project in Project Server, manually:
1. When you open one of your project, in SharePoint Ribbon you will see "Options" button and its submenu "Change Project Type". By clicking this option, you can change the existing Project Type to another one (you can select from a list of a defined Project Types). This option will always restart workflow to the first stage, to the beginning.
If you need to do this automatically, this is the code:
CHANGE EPT FROM CODE:
public void ChangeEPT(Guid projectUID, string stageName, string eptName)
{
var logService = new LogService();
var sessionService = new
PSSessionService()
{
HostName = "serverName",
// your PWA host name
SiteName = "pwa" // your PWA site name
};
PsiContextService psiContextService = new PsiContextService();
PSISvcsFactory psiSvcsFactory = new PSISvcsFactory(sessionService,
psiContextService);
Project svcProject =
psiSvcsFactory.CreateSvcClient<Project>();
Workflow svcWf =
psiSvcsFactory.CreateSvcClient<Workflow>();
SPSPagesService svcPage = new SPSPagesService(sessionService);
SPSharepointService
svcSP = new SPSharepointService(sessionService, svcPage, logService);
PSWorkflowService svcPSWf= new
PSWorkflowService(logService, svcWf, svcSP);
WorkflowDataSet workflowDS = svcWf.ReadAvailableEnterpriseProjectTypes();
List<PSWorkflowStatus>
wfStatus = svcPSWf.GetProjectWorkflowStatus(projectUID);
//Enteprise project template UID
Guid _eptUID = new
Guid();//
//Stage UID
Guid _stageGuid = new
Guid();
//stageName - must be the first stage of your workflow
//I haven't tried it with another stage, but it works if it is the first stage name
for (int
i = 0; i < wfStatus.Count; i++)
{
if (wfStatus[i].StageName == stageName)
{
_stageGuid = wfStatus[i].StageUid;
break;
}
}
//getting the enterprise project type GUID
//here we change our Project Type with another one - its name is the parameter
//you don't have to do this if you already know the guid of your EPT, you can
//just assign your guid to _eptUID variable
//just assign your guid to _eptUID variable
for (int i = 0; i
< workflowDS.EnterpriseProjectType.Count; i++)
{
if
(workflowDS.EnterpriseProjectType[i].ENTERPRISE_PROJECT_TYPE_NAME == eptName)
{
_eptUID = workflowDS.EnterpriseProjectType[i].ENTERPRISE_PROJECT_TYPE_UID;
break;
}
}
//_eptUID is the uid of our new EPT
Guid _restartGuid = svcPSWf.SubmitStage(projectUID, _eptUID, false, _stageGuid);
can you give the complete code ? i need to know what web service reference needed.
ReplyDeleteI plan to change the ept when user published from ms project using event handler depend on look up project type selected.
This is complete code. You just need to add FluentPS library to use it. This is a post where I describe use of FluentPS: http://sharepoint1on1.blogspot.com/2013/01/how-to-use-project-server-psi-functions.html?m=1
ReplyDeleteHow Do I EPT using CSOM . Please update ?
ReplyDeleteI don't know how it can be done with CSOM (or is it even possible). Sorry
DeleteVery nice Mario. This could be very useful in Powershell as a bulk edit operation.
ReplyDeleteYes, you are right.
DeleteIn 2019 is it possible to do the same?
ReplyDelete