Copy attribute from Project Area to Other Project Area programmatically
We have 2 Project Areas(A,B) sharing Process from different Project Area(C).
We have 2 Workitem types Defect,Story
Usecase 1: With in Same Project Area (A)
I am trying to create New Defect Workitem by copying over some of the fields from existing Defect Workitem.
Result:
Works completely fine for Built in and Custom Attributes
Usecase 2:Betweeen Project Areas(A and B)
I am trying to create New Defect Workitem present in PA "B" by copying over some of the fields from existing Defect Workitem present in PA "A".
Result:
Getting below error,
Exception in thread "AWT-EventQueue-0" org.eclipse.core.runtime.AssertionFailedException: assertion failed:
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:96)
at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.setValue(WorkItemImpl.java:2909)
at com.bosch.masterchild.almchildproblem.WorkItemInitialisation.execute(WorkItemInitialisation.java:48)
Why this is not Possible between Project Areas though they are having Same Process.
Code:
Getting workitemtype from ProjectArea A
workItemType = this.workItemService.findWorkItemType(this.projArea, WIConstants.typeIdentifier, null);
Getting identifiers from Workitems in ProjectArea A
WorkItemInit operation =
new WorkItemInit(this.defectObj.getSummaryWI(), this.category,
this.defectObj.getDescriptionWI(), this.defectObj.getSeverity(), this.engIdent, this.engIAtt,
this.dpIdent, this.dpIAttr);
IWorkItemHandle handle = operation.run(workItemType, null);
public class WorkItemInit extends WorkItemOperation {
private final String fSummary;
Identifier<ISeverity> severty;
private final String fDescription;
private final ICategoryHandle fCategory;
private final Identifier engValue;
private final IAttribute attrEng;
private final Identifier dpValue;
private final IAttribute dpAttr;
public WorkItemInit(final String summary, final ICategoryHandle category, final String description,
final Identifier<ISeverity> severity, final Identifier engValue, final IAttribute attrEng,
final Identifier dpValue, final IAttribute dpAttr) {
super("Initializing Work Item");
this.fSummary = summary;
this.fCategory = category;
this.fDescription = description;
this.severty = severity;
// Custom Attribute
this.engValue = engValue;
this.attrEng = attrEng;
this.dpValue = dpValue;
this.dpAttr = dpAttr;
}
@Override
protected void execute(final WorkItemWorkingCopy workingCopy, final IProgressMonitor monitor)
throws TeamRepositoryException {
IWorkItem workItem = workingCopy.getWorkItem();
workItem.setHTMLSummary(XMLString.createFromPlainText(this.fSummary));
workItem.setCategory(this.fCategory);
// Setting the Identifier and value fetched above to same workitem type in other Project Area and has enumerations same.
workItem.setValue(this.attrEng, this.engValue); // Custom Attribute
workItem.setHTMLDescription(XMLString.createFromPlainText(this.fDescription));
workItem.setSeverity(this.severty);
}
Accepted answer
This is no different from using CSV export and import. You basically have to map
- The attribute you read to the attribute you write
- The values you read to the values you write
One other answer
You r error message above does not show anything of value.
Comments
I have updated now with Code (Above).
If i understand your above statement though Same Process is used by Project Area A and B.
We should NOT pass Object retrieved from Project A for setting in Field in Project Area B.
Even Workitem type should be fetched from Project Area where we should set the values,
workItemType = this.workItemService.findWorkItemType(this.projArea, WIConstants.typeIdentifier, null);
Then we should take the value set in Workitem of Project Area A and get IAttribute in other Project Area for the same value and use it for setting.
is that right?