It's all about the answers!

Ask a question

Programmatically updating the "Acceptance Test" field of a S


Dave Draeger (4172) | asked Jan 25 '10, 2:38 p.m.
retagged Nov 14 '12, 8:20 a.m. by Morten Madsen (3053149)
I'm trying to copy over some user stories from a lotus notes database into RTC using the plain java client and have run into a snag. I have been successful in updating all standard work item fields (creator, owner, summary, description, etc) but when it comes to the custom attribute of the "Acceptance Test" field, it continues to fail and I'm not able to update that field at all.

Here are some code snippets (simplified) around how I'm trying to update the custom attribute. I've found a lot of examples around the core work item updates but haven't been able to find a clear example/explanation around the custom attributes, so any examples/help would be appreciated.

// Create a work item to set fields on
WorkItem workItem = (WorkItem) IWorkItem.ITEM_TYPE.createItem();
workItem.setSummary("My Summary");
workItem.setDescription("This is a new description");

IAttribute attr = workItemClient.findAttribute(getDefaultProjectArea(), "com.ibm.team.apt.attribute.acceptance", monitor);
if (attr != null) {
workItem.setValue(attr, "My Acceptance Test Text");
}

...... More field setting code

// Then generate a working copy, setting all of the fields
WorkItemWorkingCopy wc = workItemClient.getWorkItemWorkingCopyManager().getWorkingCopy(handle);
IDetailedStatus s = wc.save(monitor);

--------------------------------------------------------------------
After all of that, I then get the following error even though the "attr != null" check passes as not null.

java.lang.NullPointerException
at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.hasBuiltInAttribute(WorkItemImpl.java:2925)
at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.hasAttribute(WorkItemImpl.java:2918)
at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.setValue(WorkItemImpl.java:2836)
at com.ibm.ddraeger.sync.icsw.SyncBTTDesignDB.createNewWorkItemFromBTT(SyncBTTDesignDB.java:157)
at com.ibm.ddraeger.sync.icsw.SyncBTTDesignDB.addBTTItemsToJazz(SyncBTTDesignDB.java:95)
at com.ibm.ddraeger.sync.icsw.SyncBTTDesignDB.syncBTTToJazz(SyncBTTDesignDB.java:80)
at com.ibm.ddraeger.sync.icsw.SyncBTTDesignDB.main(SyncBTTDesignDB.java:63)

----------------------------------------------------------------------
Any assistance on this would be greatly appreciated. Ideally a link/code snippet of an example on getting/setting custom attributes (especially the "Acceptance Test") would be helpful.

Thanks!

--
Dave Draeger

3 answers



permanent link
pugazhenthi samidurai (26423942) | answered Mar 26 '12, 10:17 a.m.
Hi,

i want to save custom attribute of type workitem.

Like Parent Development for Development workitem.

could any suggest any idea.


Thanks ,

Pugazh

permanent link
Dave Draeger (4172) | answered Jan 25 '10, 4:23 p.m.
Thank you for the feedback, I am now able to update the Acceptance Test field. I did have one minor problem with the
workItem.setValue not liking the XMLString.createFromPlainText("My Acceptance Test Text")) parameter, but after setting
it to a standard java String it worked fine.

Thanks again.
--
Dave Draeger
IBM WebSphere Serviceability Development
"Patrick Streule" <patrick_streule> wrote in message news:hjks1p$rot$1@localhost.localdomain...
WorkItem workItem = (WorkItem) IWorkItem.ITEM_TYPE.createItem();

This is the problematic line of code. It will not correctly initialize the work item.

You could use a WorkItemOperation as described in
https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation

Or alternatively, you would use the working copy manager to create a work item for you:

IWorkItemHandle handle= manager.connectNew(IWorkItemType workItemType, IProgressMonitor monitor);
WorkItemWorkingCopy workingCopy= manager.getWorkingCopy(handle);
workingCopy.getWorkItem().setHTMLSummary(XMLString.createFromPlainText("original summary"));

IAttribute attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),
"com.ibm.team.apt.attribute.acceptance", monitor);
if (attr != null) {
workItem.setValue(attr, XMLString.createFromPlainText("My Acceptance Test Text"));
}

--
Regards,
Patrick
Jazz Work Item Team

permanent link
Patrick Streule (4.9k21) | answered Jan 25 '10, 2:53 p.m.
JAZZ DEVELOPER
WorkItem workItem = (WorkItem) IWorkItem.ITEM_TYPE.createItem();

This is the problematic line of code. It will not correctly initialize
the work item.

You could use a WorkItemOperation as described in
https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation

Or alternatively, you would use the working copy manager to create a
work item for you:

IWorkItemHandle handle= manager.connectNew(IWorkItemType workItemType,
IProgressMonitor monitor);
WorkItemWorkingCopy workingCopy= manager.getWorkingCopy(handle);
workingCopy.getWorkItem().setHTMLSummary(XMLString.createFromPlainText("original
summary"));

IAttribute attr =
workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),
"com.ibm.team.apt.attribute.acceptance", monitor);
if (attr != null) {
workItem.setValue(attr, XMLString.createFromPlainText("My
Acceptance Test Text"));
}

--
Regards,
Patrick
Jazz Work Item Team

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.