Community Tip - You can change your system assigned username to something more personal in your community settings. X
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)
Solved! Go to Solution.
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
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
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);
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
@HelesicPetr , I think there's an error in the method. When I do a Check Syntax, I get an error.
newPromotionNotice.setTypeDefinitionReference(TypedUtilityServiceHelper.service.getTypeDefinitionReference("wt.maturity.PromotionNotice|MySubtypeFullInternalName"));
There is a situation like the following in the JavaDoc.
com.ptc.core.meta.type.mgmt.server.impl.service.StandardTypedUtilityService.getTypeDefinitionReference(java.lang.String fullname)
Hi Emrec@n
There is not a syntax error.
I use it all the time
Check that you use correct class
wt.type.TypedUtilityServiceHelper
You have to use full package definition of the class if you use the code in the workflow directly.
I use IDE to write a code so I use import function to import the package.
PS> it is useful to share the error.
PetrH
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