cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Automating ChangeReview Creation and Adding Objects from Promotion Notice Using Windchill APIs

Emrec@n
8-Gravel

Automating ChangeReview Creation and Adding Objects from Promotion Notice Using Windchill APIs

 

 

// Aktif oturum kullanıcısını sakla
wt.org.WTPrincipal originalUser = wt.session.SessionHelper.manager.getPrincipal();
wt.pom.Transaction trx = new wt.pom.Transaction();

    // Promotion Notice nesnesini alın
    wt.maturity.PromotionNotice promotionNotice = (wt.maturity.PromotionNotice) primaryBusinessObject;

    // Promotion Notice'in ait olduğu konteyneri alın
    wt.inf.container.WTContainer container = promotionNotice.getContainer();
    wt.inf.container.WTContainerRef containerRef = wt.inf.container.WTContainerRef.newWTContainerRef(container);
	
	    // Promotion Notice'e bağlı nesneleri bul
    wt.fc.collections.WTSet associatedObjects = new wt.fc.collections.WTHashSet();
    wt.fc.QueryResult queryResult = wt.maturity.MaturityHelper.service.getPromotionTargets(promotionNotice);

		while (queryResult.hasMoreElements()) {
        Object target = queryResult.nextElement();
        if (target instanceof wt.doc.WTDocument || target instanceof wt.epm.EPMDocument || target instanceof wt.part.WTPart) {
            associatedObjects.add(target); // İlgili nesneleri set'e ekle
        }
    }
	
		java.util.Vector<Object> associatedVector = new java.util.Vector<>(); // java.util.Vector kullanımı
associatedVector.addAll(associatedObjects);
try {
	trx.start();
	
    // Yeni bir Review (Change Review) oluştur
    wt.change2.WTChangeReview changeReview = wt.change2.WTChangeReview.newWTChangeReview();
    changeReview.setContainerReference(containerRef); // Konteyner referansı ayarla
    changeReview.setName("Review for Promotion Notice: " + promotionNotice.getName()); // İsim belirle
    changeReview.setDescription("Automatically created Review for Promotion Notice: " + promotionNotice.getNumber()); // Açıklama ekle

    // Review'ün tipini ayarla (örnek: Review tipi)
    changeReview.setTypeDefinitionReference(
        wt.type.TypedUtilityServiceHelper.service.getTypeDefinitionReference("Review")
    );
	
	associatedVector = wt.change2.ChangeHelper2.service.storeAssociations(wt.change2.AffectedActivityData.class, changeReview, associatedVector);
	associatedVector = wt.change2.ChangeHelper2.service.saveAffectedActivityData(associatedVector);


  // Review nesnesini kaydet
   changeReview = (wt.change2.WTChangeReview) wt.fc.PersistenceHelper.manager.save(changeReview);



    trx.commit(); // İşlemi tamamla
    trx = null;   // Transaction nesnesini sıfırla

} catch (Exception e) {
    if (trx != null) {
        try {
            trx.rollback(); // İşlemi geri al
        } catch (Exception rollbackException) {
            rollbackException.printStackTrace();
        }
    }
    e.printStackTrace(); // Hataları logla

} finally {
    // Orijinal kullanıcıyı geri yükle
    wt.session.SessionHelper.manager.setPrincipal(originalUser.getName());

    // Transaction nesnesini temizle
    if (trx != null) {
        try {
            trx.rollback();
        } catch (Exception finalRollbackException) {
            finalRollbackException.printStackTrace();
        }
    }
}

 

 

Version: Windchill 12.0

 

I want to automatically initiate a ChangeReview at a specific stage within the Promotion Notice. Additionally, I want to retrieve the objects within the Promotion Notice and add them as review objects to the newly created review. How can I achieve this using Windchill APIs. I'm not having any issues creating the ChangeReview, but I am unable to add the objects from the Promotion Notice into the ChangeReview.

2 REPLIES 2

Very doable.

Here's a Promotion Request with three objects set for promotion.

d_graham_0-1732210815221.png

 

I initiate my test workflow that has a variable to store the Change Review that will be automatically created by the workflow.  This variable is used just to make it easy to open the Change Review object after it is created by the workflow.  It's not required.

d_graham_1-1732211075738.png

 

The workflow is advanced to run the code to create the Change Review and add the promotion objects to the Change Review. The workflow variable now displays a link the newly created Change Review

d_graham_2-1732211360490.png

 

Opening the Change Review object by clicking on the link show the promotion objects on the Promotion Request are now also on the Change Review object as Review Objects.

d_graham_3-1732211646739.png

 

Seems to be bombproof. 😊

Great! This is exactly what I want, could you share the code with me?

 


@d_graham wrote:

Very doable.

Here's a Promotion Request with three objects set for promotion.

d_graham_0-1732210815221.png

 

I initiate my test workflow that has a variable to store the Change Review that will be automatically created by the workflow.  This variable is used just to make it easy to open the Change Review object after it is created by the workflow.  It's not required.

d_graham_1-1732211075738.png

 

The workflow is advanced to run the code to create the Change Review and add the promotion objects to the Change Review. The workflow variable now displays a link the newly created Change Review

d_graham_2-1732211360490.png

 

Opening the Change Review object by clicking on the link show the promotion objects on the Promotion Request are now also on the Change Review object as Review Objects.

d_graham_3-1732211646739.png

 

Seems to be bombproof. 😊


 


@d_graham wrote:

Very doable.

Here's a Promotion Request with three objects set for promotion.

d_graham_0-1732210815221.png

 

I initiate my test workflow that has a variable to store the Change Review that will be automatically created by the workflow.  This variable is used just to make it easy to open the Change Review object after it is created by the workflow.  It's not required.

d_graham_1-1732211075738.png

 

The workflow is advanced to run the code to create the Change Review and add the promotion objects to the Change Review. The workflow variable now displays a link the newly created Change Review

d_graham_2-1732211360490.png

 

Opening the Change Review object by clicking on the link show the promotion objects on the Promotion Request are now also on the Change Review object as Review Objects.

d_graham_3-1732211646739.png

 

Seems to be bombproof. 😊


Announcements

Top Tags