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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. 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.

0 REPLIES 0
Announcements

Top Tags