当前位置:网站首页>Windchill - how to start workflow through API

Windchill - how to start workflow through API

2022-06-22 07:52:00 Glory eggplant



/**
*  Parameters  pbo  It is the main part of the process , It can be Windchill An existing or newly created object in the system 
*  Main items , It can be a part , file ,ECR,ECO or Problem Report  etc. 
*  Such as : WTPart, WTDocument, WTChangeRequest2, WTChangeOrder2,...
*
*  Parameters  templateName  Is the name of the process template defined under the process administrator 
*/
public void startWorkflow(WTObject pbo, String templateName ) {

String wfTemplateName = templateName ;
WTObject primaryBusinessObject = pbo ; 

WfProcess wfProcess = null;
WTContainerRef containerRef = null;
WfProcessDefinition processDefinition = null;
TeamReference teamRef = null;


if (primaryBusinessObject !=null) {

    // 1.  Based on main items WTDocument give an example 
    if (primaryBusinessObject  instanceof WTDocument) {

     WTDocument wtDocument = (WTDocument)primaryBusinessObject ;
     containerRef = wtDocument.getContainerReference();

    //2.  According to the process template name ,  Get the defined process template 
    processDefinition = 
    WfDefinerHelper.service.getProcessDefinition(wfTemplateName,containerRef );

    //3.  The group that gets the main item , Of the user's subsequent processes Context Team
    teamRef = wtDocument.getTeamId();

    //4.  establish Process.
    wfProcess = 
    WfEngineHelper.service.createProcess(processDefinition,teamRef,containerRef);

    //5.  Set process variables 
    ProcessData data  = wfProcess.getContext();

    // Set the main item process variable first 
    data.setValue("primaryBusinessObject", primaryBusinessObject )  ;

    // Set other process variables 
    data.setValue("YourAttributeKey","YourAttributeValue");

    //6.  Start process 
    wfProcess = wfProcess.start(data, true, containerRef);

    //7. Update and refresh process 
    Persistable persistable = PersistenceHelper,manager.modify(wfProcess);
    PersistenceHelper.manager.refresh(persistable);

   //8.  So far, the process has been started 

   }
}





原网站

版权声明
本文为[Glory eggplant]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202220531569108.html