Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Problem when creating a new defect in rtc

 Hello,
I am ussing Java Plain Client Libr. I want to create a new defect  from a simple java app.
I am ussing a class that extends WorkItemOperation.
and the code for my exectute method is:
@Override
protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException {
IWorkItem workItem= workingCopy.getWorkItem();
workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary));
workItem.setCategory(fCategory);
workItem.setCreator(teamRepository.loggedInContributor());
workItem.setOwner(teamRepository.loggedInContributor());
IAuditableClient client= (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);  
    List<IAttribute> customAttribs = client.resolveAuditables(workItem.getCustomAttributes(), IAttribute.FULL_PROFILE, null); 
    for (IAttribute ia : customAttribs) { 
   
    System.out.println( " attribute name:" + ia.getDisplayName()+" default value "+ia.getDefaultValue(client, workItem, null)); 
    workItem.setValue(ia,ia.getDefaultValue(client, workItem, null) );
System.out.println(" the new attribute value = "+workItem.getValue(ia)+" the value is set = "+workItem.isAttributeSet(ia));

if(ia.getDisplayName().contains("ODC Trigger"))
{
workItem.setValue(ia,existingItemCustomAtt.get(1).getValue(client, workItem, null));
}
if(ia.getDisplayName().contains("ODC Activity"))
{
workItem.setValue(ia,existingItemCustomAtt.get(2).getValue(client, workItem, null));
}
if(ia.getDisplayName().contains("ODC Impact"))
{
workItem.setValue(ia,existingItemCustomAtt.get(0).getValue(client, workItem, null));
}
    }
    workingCopy.save(null);
}
}
In the existingItemCustomAtt list I have put values from another defect for the 3 custom attributes.
The work item does not get saved. Do you know why?
 The same code but used for creating a task works... I guess that the problem are the custom attributes for ODC information when creating a defect.
Thanks

0 votes



5 answers

Permanent link
Hi Ioana,

if you use the WorkItemOperation and override it, you don't save the working copy. That is handled in the operation. Like shown in https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation .
Otherwise I would look at the exceptions that are thrown.

0 votes


Permanent link
 Like I've said, if I try to create a task, the task is created. But if I try to create a defect ( String typeIdentifier= "task";) it gives me:
Name: Save Work Item
ID: com.ibm.team.workitem.operation.workItemSave
Severity: ERROR
Name: Required Properties
ID: com.ibm.team.workitem.advisor.requiredProperties
Severity: ERROR
Summary: Attribute 'ODC Trigger' not set
Description: The 'ODC Trigger' attribute needs to be set (work item <04:43:51>).
Severity: ERROR
Summary: Attribute 'ODC Impact' not set
Description: The 'ODC Impact' attribute needs to be set (work item <04:43:51>).
Severity: ERROR
Summary: Attribute 'ODC Activity' not set
Description: The 'ODC Activity' attribute needs to be set (work item <04:43:51>).
Severity: ERROR
Name: Required Approvals
ID: com.ibm.team.workitem.advisor.requiredApprovals
Severity: OK
Name: Dynamic Required Attributes
ID: com.ibm.team.workitem.advisor.requiredAttributes
Severity: OK
Name: Attribute Validation
ID: com.ibm.team.workitem.advisor.validation
Severity: OK
Name: SPoRT Duplicate Work Item Check
ID: com.ibm.sport.rtc.process.service.operationAdvisors.duplicateWorkItemCheck
Severity: OK

0 votes


Permanent link
1. I never use workingCopy.save() in such an operation. The operation handles that outside. Try to remove that statement.

2. I use code like the below to make sure the attribute actually exists on the element (especially for modify). i have seen a bunch of people using the display name instead of the ID and fetching the wrong attribute, that actually was not defined or used for a type, in which case you just get issue. Otherwise, I can't tell. Kind of hard to debug on my end, missing the schema and the complete code.

 
            IAttribute customString = workItemClient.findAttribute(fProjectArea,
                    fCustomStringAttributeID, null);
           
            if(null!=customString){
                 if(workItem.hasCustomAttribute(customString))
                    workItem.setValue(customString, fCustomString);
            }

0 votes


Permanent link
 I've changed my execute code into
@Override
protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException {
IWorkItem workItem= workingCopy.getWorkItem();
workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary));
workItem.setCategory(fCategory);
workItem.setCreator(teamRepository.loggedInContributor());
workItem.setOwner(teamRepository.loggedInContributor());
workItem.setDuration(10000);
IAuditableClient client= (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);  
    List<IAttribute> customAttribs = client.resolveAuditables(workItem.getCustomAttributes(), IAttribute.FULL_PROFILE, null); 

IAttribute customString = workItemClient.findAttribute(projectArea, 
"ODC_Defect_Target", null); 
            
            if(null!=customString){ 
                 if(workItem.hasCustomAttribute(customString)) 
                    {
                workItem.setValue(customString, customString.getDefaultValue(client, workItem, null)); 
                System.out.println("Is set ="+workItem.isAttributeSet(customString));
                    }
                 
            } 
            IAttribute acttring = workItemClient.findAttribute(projectArea, 
"ODC_Activity", null); 
            
            if(null!=acttring){ 
                 if(workItem.hasCustomAttribute(acttring)) 
                    {
                workItem.setValue(acttring, acttring.getDefaultValue(client, workItem, null)); 
                System.out.println("Is set ="+workItem.isAttributeSet(acttring));
                    }
                 
            } 
            IAttribute impactString = workItemClient.findAttribute(projectArea, 
"ODC_Impact", null); 
            
            if(null!=impactString){ 
                 if(workItem.hasCustomAttribute(impactString)) 
                 {
                workItem.setValue(impactString, impactString.getDefaultValue(client, workItem, null)); 
                System.out.println("Is set ="+workItem.isAttributeSet(impactString));
                 }
                 
            }
}
but the same problem. 
com.ibm.team.process.common.advice.TeamOperationCanceledException: 'Save Work Item' failed. Preconditions have not been met: The 'ODC Trigger' attribute needs to be set (work item <05:26:54>).
Name: Save Work Item
ID: com.ibm.team.workitem.operation.workItemSave
Severity: ERROR
Name: Required Properties
ID: com.ibm.team.workitem.advisor.requiredProperties
Severity: ERROR
Summary: Attribute 'ODC Trigger' not set
Description: The 'ODC Trigger' attribute needs to be set (work item <05:26:54>).
Severity: ERROR
Summary: Attribute 'ODC Impact' not set
Description: The 'ODC Impact' attribute needs to be set (work item <05:26:54>).
Severity: ERROR
Summary: Attribute 'ODC Activity' not set
Description: The 'ODC Activity' attribute needs to be set (work item <05:26:54>).
Severity: ERROR
Name: Required Approvals
ID: com.ibm.team.workitem.advisor.requiredApprovals
Severity: OK
Name: Dynamic Required Attributes
ID: com.ibm.team.workitem.advisor.requiredAttributes
Severity: OK
Name: Attribute Validation
ID: com.ibm.team.workitem.advisor.validation
Severity: OK
Name: SPoRT Duplicate Work Item Check
ID: com.ibm.sport.rtc.process.service.operationAdvisors.duplicateWorkItemCheck
Severity: OK
In debug mode the code goes into all of the three setValue lines and at "Is set" it prints true in all of the three cases.
Since this morning I'm working on this issue and I honestly don;t know what to do to it anymore.

0 votes


Permanent link
If you debug this in Eclipse (see https://jazz.net/library/article/807 how to set this up), does the code find the attributes? If you don't want to debug, consider to put in System.out.println() statement and getValue() to understand if the code actually is called..

0 votes

Comments

I've put the sysout solution so I can show you... the values are set Is set =true value com.ibm.team.workitem.common.model.ILiteral:ODC_Defect_Target.literal.l6 Is set =true value com.ibm.team.workitem.common.model.ILiteral:ODC_Activity.literal.l18 Is set =true value com.ibm.team.workitem.common.model.ILiteral:ODC_Impact.literal.l16

Hi, didn#t notice the sysout. I am not sure what the issue is. Is "ODC_Impact" the ID of the attribute? I would, in my test system, remove the required attribute condition and try if the values are showing. You can enable them again later. If the code works for one type and the other type is correctly defined and you are using the correct attribute I'd, i would expect it to work.

it is possible to remove the required attribute? and yes, tge ODC_Impact is the id of the attribute.

Well, you or someone else has defined the required attributes in your process, of course you can remove them.

There is the removeCustomAttribute method .. but using it does not affect the repository workflow in any way?

Sorry, but I have used the removeAttribute for the custom attributes but I still get the same problem .. that ODC .... is not set. I really don;t know what is the source of my problem...

No, you have to go into the process template (with the eclipse client) and change it to not require the attributes for the new state. The process template has rules set in the team configuration, permissions or operational behavior. Talk to the person that created the template. Removing the attribute has the same effect - it is not there, it is not set, no save.

showing 5 of 7 show 2 more comments

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Jul 20 '12, 9:21 a.m.

Question was seen: 5,659 times

Last updated: Jul 20 '12, 11:34 a.m.

Confirmation Cancel Confirm