Forum Discussion

Former_Member's avatar
Former_Member
Accelerator III
8 years ago

Create Express ECO programatically - Affected Items don't show

Hi, I want to be able to create an Express ECO programmatically based on an existing Express ECO. I create a new Express ECO item and a number of new Affected Item records. Then I relate the Affected Items to the new Express ECO item. It all seems to work with no errors. When I open the new Express ECO item from the TOC it displays normally but does not show any of the Affected Items in the Impact Matrix. Using: <AML> <Item type='Express ECO' action='get'> <id>ID of the Express ECO I have just created programmatically OR ID of Express ECO created through the User Interface</id> <Relationships> <Item type='Express ECO Affected Item'></Item> </Relationships> </Item> </AML> I have been able to interrogate the structure that is being created by my code and via the user interface. It appears to me to be the same. Code I am using:
Innovator inn = this.getInnovator();
// ************* Testing - Use ID "1099103A004C431AB08602889B2F3EED" which is an Express ECO
Item ci = inn.newItem("Express ECO","get");
ci.setID("1099103A004C431AB08602889B2F3EED");
// ********************* End Testing
Item affectedItems = inn.newItem("Express ECO Affected Item","get");
ci.addRelationship(affectedItems);
ci = ci.apply();
if (ci.isError())
{
    return inn.newError("Error retrieving Express ECO item. Contact the PLM system administrator.");
}

// Copy the basic ECO fields from the old ECO to the new one.
string[] ecoFields = new string[] {"_non_recurring_cost","_recurring_cost","_recurring_cost_direction","_release_for_purpose_intent","change_reason",
"classification","description","owned_by_id","team_id","title"};
Item eco = inn.newItem("Express ECO","add");
for ( int i = 0; i < ecoFields.Length; i++)
{
    eco.setProperty(ecoFields,ci.getProperty(ecoFields,""));
}
Item afi = ci.getItemsByXPath("//Item[@type='Affected Item']");
// Create a new Affected item for each affected item in the old ECO
// Use the "final" Revision number as the input into the new ECO
for ( int j = 0; j < afi.getItemCount(); j++)
{
    Item itm = afi.getItemByIndex(j);
    Item newAi = inn.newItem("Affected Item","add");
    Item newAiRel = inn.newItem("Express ECO Affected Item","add");
    
    newAi.setProperty("affected_id",itm.getProperty("new_item_id"));
    newAi.setProperty("affected_type",itm.getProperty("affected_type"));
    newAi.setProperty("affected_rev",itm.getProperty("new_item_rev"));
    
    newAiRel.setRelatedItem(newAi);
    eco.addRelationship(newAiRel);
    
}
Item result = eco.apply();

if ( result.isError() )
{
    return inn.newError("Error creating ECO based on this one. XML for new ECO: " + eco.node.OuterXml );
}

return this;
Any suggestions what I might be missing to have this create a valid Express ECO? Thanks, Brian.

2 Replies

  • Bryan, I haven't tested it recently but have you tried adding an action on the affected Item. I think that may be what's missing here. The only lines you see without actions in the impact matrix are the items coming from the impact analysis process, they are not actually affected items. I think you need to add an action.
    newAi.setProperty("item_action","Review");