Conditional Execution of Automatic Promotion Requests and Assignment of 'Created By' Role"
Version: Windchill 12.0
Hello,
In Windchill, I am creating an automatic promotion request at the end of the change review process with the following code. However, I have two questions that I couldn't resolve.
Question: I have defined a boolean variable "Should automatic promotion request be initiated?" within the activity at the approval stage for the automatic promotion request code. I want the code below to execute if this variable is true; otherwise, it should not execute. How can I achieve this?
Question: I want the person in the submitter role who initiated the change review process to be assigned as the "created by" for the promotion request. These questions might be simple, but I haven't been able to find a solution.
"Code to Automatically Create Promotion Requests for Documents in Change Review"
wt.pom.Transaction trx = new wt.pom.Transaction();
wt.change2.WTChangeReview changeReview = (wt.change2.WTChangeReview) primaryBusinessObject;
// ChangeReview nesnesinden kapsayıcıyı alıyoruz
wt.inf.container.WTContainer container = changeReview.getContainer();
wt.inf.container.WTContainerRef containerRef = wt.inf.container.WTContainerRef.newWTContainerRef(container);
// ChangeReview nesnesinden etkilenen dokümanları alıyoruz
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); // WTDocument nesnelerini koleksiyona ekliyoruz
}
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.setTypeDefinitionReference(wt.type.TypedUtilityServiceHelper.service.getTypeDefinitionReference("tr.com.aselsan.hbtwinctest02.HBT.PromotionNoticeTest"));
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);
// Assign iteration creator with submitterRef before saving Promotion Notice
// wt.vc.VersionControlHelper.assignIterationCreator((wt.vc.Versioned) pn, submitterRef);
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;
} catch (Exception e) {
if (trx != null) {
trx.rollback();
}
e.printStackTrace(); // Hata durumunu işleyin veya kaydedin
}
"The assignment code I used when creating a different object before, but this code did not work (perhaps I used it incorrectly)."
// Assign iteration creator with submitterRef before saving Promotion Notice
// wt.vc.VersionControlHelper.assignIterationCreator((wt.vc.Versioned) pn, submitterRef);

