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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

How to retrieve the "promoted from state" for promotion targets using an expression robot in a promotion request workflow

bwilcox
12-Amethyst

How to retrieve the "promoted from state" for promotion targets using an expression robot in a promotion request workflow

We are using Windchill 10.2 M030.

I need to know how to retrieve the "promoted from state" for promotion targets/objects in a promotion request. I know how to query the promotion targets and get attribute values from them, but I have not been able to find where the "promoted from state" value is stored or how to retrieve it.

For example, if an object is submitted for promotion from the "INWORK" state to the "RELEASED" state, I want to retrieve the "INWORK" state value.

Here is the code I am using to get the promotion targets and some of the code for processing them:

wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice)primaryBusinessObject;

wt.maturity.StandardMaturityService p = new wt.maturity.StandardMaturityService();

wt.fc.QueryResult pn_targets = (wt.fc.QueryResult) p.getPromotionTargets(pn);

while (pn_targets.hasMoreElements()) {

     Object myObject = pn_targets.nextElement();

     typeName = wt.type.TypedUtilityServiceHelper.service.getExternalTypeIdentifier((wt.type.Typed)myObject);     // store object type

}

ACCEPTED SOLUTION

Accepted Solutions
RandyJones
20-Turquoise
(To:bwilcox)

Ben Wilcox wrote:

We are using Windchill 10.2 M030.

I need to know how to retrieve the "promoted from state" for promotion targets/objects in a promotion request.

Ben: Check out LifeCycleHelper.service.getHistory()

There are several previous posts with some example on using this ie:

Maturity History for an Object

Re: How to set state of objects back to the state when they started the workflow?

View solution in original post

3 REPLIES 3
RandyJones
20-Turquoise
(To:bwilcox)

Ben Wilcox wrote:

We are using Windchill 10.2 M030.

I need to know how to retrieve the "promoted from state" for promotion targets/objects in a promotion request.

Ben: Check out LifeCycleHelper.service.getHistory()

There are several previous posts with some example on using this ie:

Maturity History for an Object

Re: How to set state of objects back to the state when they started the workflow?

jcrowe-2
4-Participant
(To:bwilcox)

 
jcrowe-2
4-Participant
(To:bwilcox)

So I spent some time looking into this one and have a solid fix for you.  Essentially you want to query the PromotionTarget link by specifying a Boolean value of false as the 2nd parameter (so you were close):  wt.maturity.MaturityHelper.service.getPromotionTargets(pn, false);  This gives you the PromotionTarget object which holds the promote from state value (pt.getCreateState()).  You can get the Persistable from the PromotionTarget if needed later.  In this example, I am getting the promote from state value for a Promotion notice that holds EPMDocs.  Then I set the EPMDoc to the promoted from state value so that the PromotionNotice can be refreshed with a later iteration.

 

/*********************************************************
 * Get PromotionNotice
 * Query for PromotionTarget Links (these are the promotion objects)
 * Get Promoted from State/
 * Check for/Get latest iteration of EPMDocument (you can only set state on latest iteration)
 * Set EPMDocument to promotedFromState
 * Refresh Promotion notice
 ************************************************************/

/*Get PromotionNotice*/
wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice)primaryBusinessObject;  
/*Query for PromotionTarget links (Promotion Notice, false)*/
wt.fc.QueryResult promotionObjectLinks = wt.maturity.MaturityHelper.service.getPromotionTargets(pn, false);
while(promotionObjectLinks.hasMoreElements()){
  try{
   wt.maturity.PromotionTarget pt = (wt.maturity.PromotionTarget)promotionObjectLinks.nextElement();
   /*Get Promoted from State from PromotionTarget*/
   wt.lifecycle.State promotedFromState = pt.getCreateState();  
  
   /*Get Promotion Targets persistable and check for latest iteration of EPMDocument*/  
   wt.epm.EPMDocument epmDoc = (wt.epm.EPMDocument)pt.getRoleBObject();
   if (!epmDoc.isLatestIteration())
   {
    wt.epm.EPMDocument latestEPMDoc = (wt.epm.EPMDocument)wt.vc.VersionControlHelper.service.getLatestIteration(epmDoc, false);
    //Set latest EPMDocument to promotedFromState   
    wt.lifecycle.LifeCycleHelper.service.setLifeCycleState((wt.lifecycle.LifeCycleManaged)latestEPMDoc, promotedFromState);
   } 
   } catch(Exception wte) {
    wte.printStackTrace();      
    } 
  }

try {
 // Refresh Promotion Notice with latest iterations of promotion objects
 com.ptc.windchill.enterprise.maturity.PromotionNoticeWorkflowHelper.refresh(pn);  
 wt.maturity.MaturityServerHelper.service.lockTargets(pn);
} catch (Exception wte){
 wte.printStackTrace();
}

Announcements


Top Tags