It's all about the answers!

Ask a question

how to use setValue(IAttribute attribute, Object value) method


vikrant kamble (132876) | asked Jul 01 '15, 7:54 a.m.
edited Jul 01 '15, 7:57 a.m.
Hi All,
I wrote code to set value of work Item attribute after work item is saved(operation participant on work item save operation).
Work Item contains "ID1" as custom attribute and its type is small string.

following is code snippet I wrote to set value of work item attribute.
IWorkItem newWorkItem = (IWorkItem) auditable;
IProjectAreaHandle projectareahandle=newWorkItem.getProjectArea();

IWorkItemCommon workitemcommon=(IWorkItemCommon)getService(IWorkItemCommon.class);
IAttribute attribute=workitemcommon.findAttribute(projectareahandle, "id1", monitor);
                        
                if(newWorkItem.hasAttribute(attribute))
                {
                    newWorkItem.setValue(attribute,"one");
                 
                }
                System.out.println("successful");
               
            }catch (Exception e)
            {

                System.out.println(e);
                System.out.println("not successful");
               
            }

This code is not working.
 After work item is saved value of "ID1" was not set. but  "System.out.println("successful"); " statement is getting executed.



following is code snippet I wrote to get value of work item attribute.
IWorkItem newWorkItem = (IWorkItem) auditable;
IProjectAreaHandle projectareahandle=newWorkItem.getProjectArea();
   IWorkItemCommon workitemcommon=(IWorkItemCommon)getService(IWorkItemCommon.class);
 IAttribute attribute=workitemcommon.findAttribute(projectareahandle, "id1", monitor);
 String value="";
               
  try
   {           
               
    if(newWorkItem.hasAttribute(attribute))
        {
                value=(String)newWorkItem.getValue(attribute);
        }
          System.out.println(value);
           System.out.println("successful");
          }catch (Exception e)
            {
                System.out.println(e);
                System.out.println("not successful");
            }

this code is working perfectly. I can see the value of attribute "ID1" .

Am I missing something when I am using setValue(IAttribute attribute, Object value) method.

Thank You.



One answer



permanent link
Ralph Schoon (59.4k23642) | answered Jul 01 '15, 8:33 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You need to have an attribute of type String to successfully do:


newWorkItem.setValue(attribute,"one");


Just Starting With Extending RTC?

If you just get started with extending Rational Team Concert, or create API based automation, start reading this and the linked posts to get some guidance on how to set up your environment. Then I would suggest to read the article Extending Rational Team Concert 3.x and perform the Rational Team Concert 4.0 Extensions Workshop. This provides you with a development environment and with a lot of example code and information that is essential to get started. If you have already done the Rational Team Concert 4.0 Extensions Workshop you can just perform Lab1 to setup your development environment for debugging.

You should be able to use the code attached to this post in the development environment you set up in the Rational Team Concert 4.0 Extensions Workshop and get your own extensions working there as well.

If you want to create code with the Plain Java Client Libraries or the RTC Client SDK please also work through Understanding and Using the RTC Java Client API, to understand the basics of the API and how you can use Eclipse to debug the code. Working with Work Item Attributes is also a useful resource to understand how work item attributes work.

Comments
vikrant kamble commented Jul 01 '15, 8:56 a.m.

Hi Ralph
I checked in my Project Area, there are string list and small string as attribute type but there is no attribute type as "string".
I used "small string" as attribute type for my custom attribute.
 


Ralph Schoon commented Jul 01 '15, 9:30 a.m. | edited Jul 01 '15, 9:31 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

All the HTML, small string, medium string, large string and what not attribute types are of Java type "String" inside the API. You can see what they are during debugging.


vikrant kamble commented Jul 01 '15, 9:39 a.m.

Is it valid to use attribute type as small string in my case.


vikrant kamble commented Jul 01 '15, 9:42 a.m.

Is it valid to use small string as attribute type in this case.
Is there any method to display attribute value in Work Item editor.


Ralph Schoon commented Jul 02 '15, 3:16 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I am sorry, but as long as you don't work through the examples already provided, it is impossible to help you.

Work item attributes of type small, medium, large string and HTML can be cast to String. You would be able to see that in the debugger, if you had followed the links provided above and done the Rational Team Concert 4.0 Extensions Workshop.

In addition if you try to understand how to customize the RTC work item process, perform

Your answer


Register or to post your answer.