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

Conditional Execution of Automatic Promotion Requests and Assignment of 'Created By' Role"

  • July 19, 2024
  • 1 reply
  • 1633 views

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.

  1. 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?

  2. 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);

 

@HelesicPetr, I believe you can help with this. I would really appreciate your assistance. Have a great day.

Best answer by HelesicPetr

@Emrec@n 

For the creator, I would try to use setPrincipal with the name of user that should be used

usually you get session principal store it as a original user variable

then change the session to user who should save the object

save the object

set the session user back to original user.

 

// get the session user
wt.session.SessionHelper.manager.getPrincipal();
// set the session user
wt.session.SessionHelper.manager.setPrincipal("userName");

 

 PetrH

1 reply

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

Hi @Emrec@n 

1. You can use the variable in the condition and based on that value go to a right way in the workflow path 

usually copy the variable from user task to global variable in the workflow. it is ootb function. 

2. I guess that the method assignIterationCreator can not be used to the object that is not versioned. Promotion Request does not have revisions and iterations.. 

PetrH

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

@HelesicPetr 

Thank you very much for your guidance. How can I copy the selected value within the Activity to a global variable? Do you have a ready method for this? Finally, what method can I use to assign the user to the promotion notice? Do you have any suggestions?🙏🙏🙏

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

Hi @Emrec@n 

It is OOTB function in the workflow, that does not need any coding.

HelesicPetr_0-1721388981447.png

 

PetrH