It's all about the answers!

Ask a question

Copy attribute from Project Area to Other Project Area programmatically


vinitha dsouza (14719128) | asked May 04 '17, 9:09 a.m.
edited May 05 '17, 9:03 a.m.


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


permanent link
Ralph Schoon (63.2k33646) | answered May 05 '17, 9:39 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited May 08 '17, 4:05 a.m.

 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
For the attribute, if you have a shared process, the ID's are the same, but the IAttribute is different, so you have to look the attribute IAttribute object up, it is different from the one you get from the source attribute.

The conversion of data depends. It is trivial to pass a string or an int or a boolean value, as that is by value and the value is primitive. Anything more complex needs to be looked up. "Found in", "Planned For", Category,....., Enumerations anything not a trivial object you need to read the original value and then find the target object based on that.

Look at the work item command line modify work item or the import. It does the same and searches anything not trivial by ID in the target. process.

For the copy it is irrelevant, if the project areas inherit the same process. The only simplification is that the ID's for process elements will be the same and you should find the enumeration values. 

Other items such as iterations, timelines, team area hierarchy, categories will be different. 

vinitha dsouza selected this answer as the correct answer

One other answer



permanent link
Ralph Schoon (63.2k33646) | answered May 05 '17, 2:17 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You r error message above does not show anything of value. 


It is absolutely possible to copy data over. However, even if the attributes in the different project areas have the sane ID and value types, they are different attributes and you will have to find the IAttribute in both project areas and you will have to map values to be able to set them. E.g. a timeline or an iteration even if the ID is the same they are different objects in the different project areas and you will have to look them up using the ID and can't just pass the old object.


Comments
vinitha dsouza commented May 05 '17, 9:07 a.m. | edited May 05 '17, 9:08 a.m.

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?

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.