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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Translate the entire conversation x

Update Value of an Attribute on Resulting Objects (type EPMDocument) through Expression Robot

PA_11085333
7-Bedrock

Update Value of an Attribute on Resulting Objects (type EPMDocument) through Expression Robot

Hello! I am looking for some help with updating the value of an attribute that exists on resulting objects of a change activity through the use of an expression robot in the workflow of the change activity. The resources I've been able to find all seem to call out the object that's having its attribute modified as the primarybusinessobject, so where I am having trouble is calling to the resulting objects while the change activity is the primarybusinessobject of the workflow.
 
I tried the following, but had the error returned "WTChangeActivity2 cannot be converted to FormDataHolder"
 

wt.change2.WTChangeActivity2 changeTask = (wt.change2.WTChangeActivity2) primaryBusinessObject;

 

java.util.Vector results = com.ptc.windchill.enterprise.changeable.ChangeableDataFactory.getResultingObjects(changeTask);

ACCEPTED SOLUTION

Accepted Solutions

I'm happy to share I believe I have something that works! I didn't realize that I needed to Cast to a Workable since the checkout method was being cast to a changeable. The following expression successfully checked out the files, applied the desired string to the attribute on each resulting object (I did test to make sure it worked on multiple) and then checked the files back in. Thank you for your help!

 

wt.change2.ChangeActivity2 changeActivity = (wt.change2.ChangeActivity2) primaryBusinessObject;
 
wt.fc.QueryResult theChangeablesAfterResult = wt.change2.ChangeHelper2.service.getChangeablesAfter(changeActivity,false);
 
while (theChangeablesAfterResult.hasMoreElements()) {
Object element = theChangeablesAfterResult.nextElement();
 
if (element instanceof wt.change2.ChangeRecord2) {
wt.change2.ChangeRecord2 changeRecord = (wt.change2.ChangeRecord2) element;
wt.change2.Changeable2 theChangeable = (wt.change2.Changeable2) changeRecord.getChangeable2();
 
//Get check out folder for the current user in the session
wt.folder.Folder checkoutFolder = wt.vc.wip.WorkInProgressHelper.service.getCheckoutFolder();
 
//Cast to Workable (required for checkout)
wt.vc.wip.Workable workable = (wt.vc.wip.Workable) theChangeable;
 
//Check out object 
wt.vc.wip.CheckoutLink chklink = wt.vc.wip.WorkInProgressHelper.service.checkout(workable, checkoutFolder, "Check out comment");
wt.epm.EPMDocument wrk = (wt.epm.EPMDocument) chklink.getWorkingCopy();
  
    com.ptc.core.lwc.server.PersistableAdapter adapter = new com.ptc.core.lwc.server.PersistableAdapter(wrk,null,null,new com.ptc.core.meta.common.UpdateOperationIdentifier());
 
// Load the attribute
    adapter.load("Watermark");
 
    // Set the new value
    adapter.set("Watermark", "TestWatermark");
 
    // Apply the change
    adapter.apply();
 
    // Save to database
    PersistenceHelper.manager.modify(wrk);
 
// Check in object
   wt.vc.wip.WorkInProgressHelper.service.checkin(wrk, "Check in comment");
}
}
 

View solution in original post

5 REPLIES 5

Could you share some more of the code you're trying?

 

Essentially I think you need to navigate from the ECN to the Resulting Objects. A first step would be this: https://www.ptc.com/en/support/article/CS55955?source=search

 

MTH
12-Amethyst
12-Amethyst
(To:PA_11085333)

 

PA_11085333

You can use this code snippet

 

ChangeActivity2 changeActivity = (ChangeActivity2) primaryBusinessObject;
QueryResult theChangeablesAfterResult = ChangeHelper2.service.getChangeablesAfter(changeActivity,
false);
while (theChangeablesAfterResult.hasMoreElements()) {
Object element = theChangeablesAfterResult.nextElement();
if (element instanceof ChangeRecord2) {
changeRecord = (ChangeRecord2) element;
Changeable2 theChangeable = changeRecord.getChangeable2();

PA_11085333
7-Bedrock
(To:MTH)

Thank you both for the responses! I've used your suggestions to get to the below state of the expression. The issue I'm having now is that " ChangeHelper2.service.getChangeablesAfter" is returning the error:

 

     " error: package ChangeHelper2 does not exist".

 

When I search for it in the JavaDoc, ChangeHelper2 doesn't have the getChangeablesAfter method. What does have that method is what @joe_morton suggested, (wt.change2.ChangeService2.getChangeablesAfter) but that returns the error:

 

      "error: non-static method getChangeablesAfter(ChangeActivityIfc,boolean) cannot be referenced from a static context".

Below is the entire code I'm working with. I'm going to continue playing around to see what I can get going but I do believe this is great progress!

______________________________________________________________________________________________________________

wt.change2.ChangeActivity2 changeActivity = (wt.change2.ChangeActivity2) primaryBusinessObject;


wt.fc.QueryResult theChangeablesAfterResult = ChangeHelper2.service.getChangeablesAfter(changeActivity,false);


while (theChangeablesAfterResult.hasMoreElements()) {
Object element = theChangeablesAfterResult.nextElement();
 
if (element instanceof wt.change2.ChangeRecord2) {
wt.change2.ChangeRecord2 changeRecord = (wt.change2.ChangeRecord2) element;
wt.change2.Changeable2 theChangeable = (wt.change2.Changeable2) changeRecord.getChangeable2();


    com.ptc.core.lwc.server.PersistableAdapter adapter = new com.ptc.core.lwc.server.PersistableAdapter(theChangeable,null,null,new com.ptc.core.meta.common.UpdateOperationIdentifier());
 
// Load the attribute
    adapter.load("Watermark");


    // Set the new value
    adapter.set("Watermark", "TestWatermark");


    // Apply the change
    adapter.apply();


    // Save to database
    PersistenceHelper.manager.modify(theChangeable);
}
}

 

An Update: It looks like I needed to change "ChangeHelper2.service.getChangeablesAfter" to "wt.change2.ChangeHelper2.service.getChangeablesAfter". This made the Syntax acceptable for the Expression Robot. I ran this and the expression got hung up. I can see from the WfUserWorkQueue that the issue is that the file isn't being checked out before it's updated. I'm currently working through making that happen. This is what I have so far but it's not functional:

 

wt.change2.ChangeActivity2 changeActivity = (wt.change2.ChangeActivity2) primaryBusinessObject;
 
wt.fc.QueryResult theChangeablesAfterResult = wt.change2.ChangeHelper2.service.getChangeablesAfter(changeActivity,false);
 
while (theChangeablesAfterResult.hasMoreElements()) {
Object element = theChangeablesAfterResult.nextElement();
 
if (element instanceof wt.change2.ChangeRecord2) {
wt.change2.ChangeRecord2 changeRecord = (wt.change2.ChangeRecord2) element;
wt.change2.Changeable2 theChangeable = (wt.change2.Changeable2) changeRecord.getChangeable2();
 
//Get check out folder for the current user in the session
wt.folder.Folder checkoutFolder = wt.vc.wip.WorkInProgressHelper.service.getCheckoutFolder();
 
//Check out object 
wt.vc.wip.CheckoutLink chklink = wt.vc.wip.WorkInProgressHelper.service.checkout(theChangeable, checkoutFolder, "Check out comment");
wt.epm.EPMDocument wrk = (wt.epm.EPMDocument) chklink.getWorkingCopy();
  
    com.ptc.core.lwc.server.PersistableAdapter adapter = new com.ptc.core.lwc.server.PersistableAdapter(wrk,null,null,new com.ptc.core.meta.common.UpdateOperationIdentifier());
 
// Load the attribute
    adapter.load("Watermark");
 
    // Set the new value
    adapter.set("Watermark", "TestWatermark");
 
    // Apply the change
    adapter.apply();
 
    // Save to database
    PersistenceHelper.manager.modify(theChangeable);
 
// Check in object
   wt.vc.wip.WorkInProgressHelper.service.checkin((wt.vc.wip.Workable) wrk, "Check in comment");
}
}
 

I'm happy to share I believe I have something that works! I didn't realize that I needed to Cast to a Workable since the checkout method was being cast to a changeable. The following expression successfully checked out the files, applied the desired string to the attribute on each resulting object (I did test to make sure it worked on multiple) and then checked the files back in. Thank you for your help!

 

wt.change2.ChangeActivity2 changeActivity = (wt.change2.ChangeActivity2) primaryBusinessObject;
 
wt.fc.QueryResult theChangeablesAfterResult = wt.change2.ChangeHelper2.service.getChangeablesAfter(changeActivity,false);
 
while (theChangeablesAfterResult.hasMoreElements()) {
Object element = theChangeablesAfterResult.nextElement();
 
if (element instanceof wt.change2.ChangeRecord2) {
wt.change2.ChangeRecord2 changeRecord = (wt.change2.ChangeRecord2) element;
wt.change2.Changeable2 theChangeable = (wt.change2.Changeable2) changeRecord.getChangeable2();
 
//Get check out folder for the current user in the session
wt.folder.Folder checkoutFolder = wt.vc.wip.WorkInProgressHelper.service.getCheckoutFolder();
 
//Cast to Workable (required for checkout)
wt.vc.wip.Workable workable = (wt.vc.wip.Workable) theChangeable;
 
//Check out object 
wt.vc.wip.CheckoutLink chklink = wt.vc.wip.WorkInProgressHelper.service.checkout(workable, checkoutFolder, "Check out comment");
wt.epm.EPMDocument wrk = (wt.epm.EPMDocument) chklink.getWorkingCopy();
  
    com.ptc.core.lwc.server.PersistableAdapter adapter = new com.ptc.core.lwc.server.PersistableAdapter(wrk,null,null,new com.ptc.core.meta.common.UpdateOperationIdentifier());
 
// Load the attribute
    adapter.load("Watermark");
 
    // Set the new value
    adapter.set("Watermark", "TestWatermark");
 
    // Apply the change
    adapter.apply();
 
    // Save to database
    PersistenceHelper.manager.modify(wrk);
 
// Check in object
   wt.vc.wip.WorkInProgressHelper.service.checkin(wrk, "Check in comment");
}
}
 
Announcements
Top Tags