How to create new workitem with workitem type attributes?
Hi,
i have developed the plain java code for create new workitem. Its working fine. But i want to know How to add workitem type attributes. i have followed the below link. https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation Thanks, Glory |
7 answers
This may helps. This is the sample code I wrote as "server side" plugin. Not sure if it works for client as well. test1, test2, test3 is custom attributes (integer type), and it calculate test3 = test1 + test3, then set the value to test3 via workitem.setValue (IAttibute, Value).
// Obtain project area and workitem server. IProjectAreaHandle iProjectArea = workItem.getProjectArea(); IWorkItemServer wiServer = getService(IWorkItemServer.class); // Obtain custom attribute objects, and their values // IAttribute test1 = wiServer.findAttribute(iProjectArea, "test1", null); IAttribute test2 = wiServer.findAttribute(iProjectArea, "test2", null); IAttribute test3 = wiServer.findAttribute(iProjectArea, "test3", null); Integer test1Value = (Integer) workItem.getValue(test1); Integer test2Value = (Integer) workItem.getValue(test2); // Calculate custom atrribute value based on other attribute values. Integer test3Value = test1Value + test2Value; // Update custom attributes. // com.ibm.customatributes.test3 workItem.setValue(test3, (Object) test3Value); |
Hi,
Thank you for your response. I can able to add string and integer type custom attributes. But i want to workitem type of custom attributes. like parent to a workitem or customer to a workitem etc. Thanks, Pugazh |
Ralph Schoon (63.6k●3●36●46)
| answered Mar 28 '12, 4:44 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Can you please be more specific on what you want to do? In General attributes are all handled alike. Based on what data you have the calls would look different.
It is a difference if you want to create a parent or other relationship or if you want to set a value or add something to a list. If you have an ID you can search for the attribute e.g. using
There are other methods to get the custom attributes as a list from the work item. Look at the methods provided. If you have that you can get to data about the Attribute, including types. You need to create objects of the type (depends on the type how to create values) you store and can then set the value similar to the other attributes. I haven't tried Attributes of type WorkItemList but assume there is a difference, where you get the list and add the value there. |
Hi,
find my workiteminitialization code below. Its working fine. But i want to add value to the attribute of type workitem. Example : Product Code is the attribute of the type workitem. How can i set the value to this attribute. Value of this attribute is must be another one workitem. public class WorkItemInitialization extends AbstractWorkItemOperation { private String fSummary; private ICategoryHandle fCategory; private IAttribute iattribute; public WorkItemInitialization(String summary, ICategoryHandle category, IAttribute ia,IWorkItemClient workItemClient) { super("Initializing Work Item"); fSummary = summary; fCategory = category; iattribute = ia; this.workItemClient = workItemClient; } protected void execute(WorkItemWorkingCopy workingCopy,IProgressMonitor monitor) throws TeamRepositoryException { IWorkItem workItem = workingCopy.getWorkItem(); workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary)); java.util.Date date= new java.util.Date(); String str_date="08-05-2012"; DateFormat formatter ; Date date1 = null ; formatter = new SimpleDateFormat("dd-M-yy"); try { date1 = (Date)formatter.parse(str_date); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } java.sql.Timestamp timeStampDate = new Timestamp(date1.getTime()); System.out.println("Today is " +timeStampDate); workItem.setCategory(fCategory); workItem.setDueDate(timeStampDate); IAttribute attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.Planned_Start_Date", monitor); if (attr != null) { workItem.setValue(attr,timeStampDate); } attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.Planned_Target_Date", monitor); if (attr != null) { workItem.setValue(attr,timeStampDate); } } } Thanks Glory |
Hi,
Thanks for your response. I have found the solution. check my code blow. public class WorkItemInitialization extends AbstractWorkItemOperation { private String fSummary; private ICategoryHandle fCategory; private IAttribute iattribute; IWorkItem iparent; IWorkItemHandle target; public WorkItemInitialization(String summary, ICategoryHandle category, IWorkItem parent, IWorkItemHandle parent2, IAttribute ia,IWorkItemClient workItemClient) { super("Initializing Work Item"); fSummary = summary; fCategory = category; iattribute = ia; iparent = parent; target = parent2; this.workItemClient = workItemClient; } protected void execute(WorkItemWorkingCopy workingCopy,IProgressMonitor monitor) throws TeamRepositoryException { IWorkItem workItem = workingCopy.getWorkItem(); workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary)); java.util.Date date= new java.util.Date(); String str_date="08-05-2012"; DateFormat formatter ; Date date1 = null ; formatter = new SimpleDateFormat("dd-M-yy"); try { date1 = (Date)formatter.parse(str_date); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } java.sql.Timestamp timeStampDate = new Timestamp(date1.getTime()); System.out.println("Today is " +timeStampDate); workItem.setCategory(fCategory); workItem.setDueDate(timeStampDate); IAttribute attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.Planned_Start_Date", monitor); if (attr != null) { workItem.setValue(attr,timeStampDate); } attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.Planned_Target_Date", monitor); if (attr != null) { workItem.setValue(attr,timeStampDate); } attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.parent_dev", monitor); System.out.println("------------------------------"); System.out.println(attr); System.out.println("------------------------------"); if (attr != null) { workItem.setValue(attr,iparent ); } setParent(workingCopy,iparent); } private void setParent(WorkItemWorkingCopy wc, IWorkItem parent) { IEndPointDescriptor referenceType= WorkItemEndPoints.PARENT_WORK_ITEM; IReference reference= WorkItemLinkTypes.createWorkItemReference(parent); wc.getReferences().add(referenceType, reference); } } Thanks Glory |
hi,
i m having one query(created by me) and i want to run the same query programmatically can anyone tell me any api for the same? thanks in advance |
hi, could you tell me how to set value for attribute WorkItemList type and the HTML type.
|
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.