Skip to main content
8-Gravel
July 18, 2024
Solved

How can Get a Workflow Process Template with name and ID information

  • July 18, 2024
  • 2 replies
  • 1764 views

Version: Windchill 12.1

 

Hello,

 

I want to automatically create a Promotion Request for the documents reviewed within the Change Review. I have achieved this with the code shared below. However, since I have not defined any workflow process in the Promotion Notice, no workflow starts. For this, I reached the method shared below. However, I cannot figure out how to obtain the WfProcessTemplate. I have the name and ID of this template, but I couldn't retrieve the template using them.

Code for creating the Promotion Request:

 

wt.pom.Transaction trx = new wt.pom.Transaction();

 

 

 

wt.change2.WTChangeReview changeReview = (wt.change2.WTChangeReview) primaryBusinessObject;

 

 

 

// Retrieve the container from the ChangeReview object

 

wt.inf.container.WTContainer container = changeReview.getContainer();

 

wt.inf.container.WTContainerRef containerRef = wt.inf.container.WTContainerRef.newWTContainerRef(container);

 

 

 

// Retrieve the affected documents from the ChangeReview object

 

wt.fc.QueryResult queryResult = wt.change2.ChangeHelper2.service.getChangeables(changeReview);

 

wt.fc.collections.WTSet set = new wt.fc.collections.WTHashSet();

 

 

 

while (queryResult.hasMoreElements()) {

 

    wt.doc.WTDocument document = (wt.doc.WTDocument) queryResult.nextElement();

 

    set.add(document); // Add WTDocument objects to the collection

 

}

 

 

 

try {

 

    trx.start();

 

 

 

    wt.maturity.MaturityBaseline maturityBaseline = wt.maturity.MaturityBaseline.newMaturityBaseline();

 

    maturityBaseline.setContainerReference(containerRef);

 

    maturityBaseline = (wt.maturity.MaturityBaseline)wt.fc.PersistenceHelper.manager.save(maturityBaseline);

 

 

 

    wt.maturity.PromotionNotice pn = wt.maturity.PromotionNotice.newPromotionNotice("Custom_Promotion_Request");

 

    pn.setPromotionDate(new java.sql.Timestamp(System.currentTimeMillis()));

 

    pn.setContainer(container);

 

    pn.setContainerReference(containerRef);

 

    pn.setMaturityState(wt.lifecycle.State.toState("RELEASED"));

 

    pn.setDescription("theDescription");

 

    pn.setConfiguration(maturityBaseline);

 

 

 

    wt.vc.baseline.BaselineHelper.service.addToBaseline(set, pn.getConfiguration());

 

    pn = wt.maturity.MaturityHelper.service.savePromotionNotice(pn);

 

    wt.maturity.MaturityHelper.service.savePromotionTargets(pn, set);

 

 

 

    trx.commit();

 

    trx = null;

 

 

 

} finally {

 

    if (trx != null) {

 

        trx.rollback();

 

    }

 

}

 

Code for starting the Promotion Notice with a process:

 

wt.maturity.MaturityService.startPromotionProcess(PromotionNotice, WfProcessTemplate)

Best answer by HelesicPetr

Hi @Emrec@n 

I have one suggestion.

Create new subtype of your promotion request, define specific new lifecycle 

and assignee a workflow to first state of the lifecycle. 

Create the subtype by your code and also do not  forget to set the subtype as instantiable to no

Users won't create it but you can by the code.

 

If the PR is created the workflow will be started based on the lifecycle. 

 

PetrH

2 replies

HelesicPetr
22-Sapphire II
22-Sapphire II
July 18, 2024

Hi @Emrec@n 

I have one suggestion.

Create new subtype of your promotion request, define specific new lifecycle 

and assignee a workflow to first state of the lifecycle. 

Create the subtype by your code and also do not  forget to set the subtype as instantiable to no

Users won't create it but you can by the code.

 

If the PR is created the workflow will be started based on the lifecycle. 

 

PetrH

Emrec@n8-GravelAuthor
8-Gravel
July 18, 2024

Hello @HelesicPetr 

 

This idea sounds good. However, how should I define the subtype I created in the code, and what changes do I need to make in the code? For example, how should I modify the above code for a promotion subtype named XXX?

 

For example, like this?

pn = wt.maturity.MaturityHelper.service.savePromotionNotice|XXX(pn);

HelesicPetr
22-Sapphire II
22-Sapphire II
July 18, 2024

Hi @Emrec@n 

Before the save, set the type reference

newPromotionNotice.setTypeDefinitionReference(TypedUtilityServiceHelper.service.getTypeDefinitionReference("wt.maturity.PromotionNotice|MySubtypeFullInternalName"));
newPromotionNotice = MaturityHelper.service.savePromotionNotice(newPromotionNotice);

PetrH

13-Aquamarine
August 2, 2024

Hi,

You can do as below. As the Workflow of the Promotion is configurable through preference, it is a good way to check the required preference.

 

//Get the Workflow Template. This will get it through preference set in the container.

WfProcessTemplate promotionWfProcessTemplate = PromotionRequestHelper.getWorkflowTemplate(containerRef, State.toState("OPEN"), null);

//Start the Process.
MaturityHelper.service.startPromotionProcess(promotionNotice, promotionWfProcessTemplate);

 

NOTE: This will be a post transaction call.

 

Thanks,

Thiaga