It's all about the answers!

Ask a question

How to fetch specific field of workitem?


Nilesh Patil (1732749) | asked Sep 02 '13, 2:21 a.m.
I want to write code to fetch specific field of workitem using client api code. I have workitem id.
I have written code like,
workItemClient.findWorkItemById(Integer.parseInt(workitemIdArray[i].trim()),
                             ItemProfile.<IWorkItem>createProfile(ITEM_TYPE,                  AuditablesHelper.AUDITABLE_SMALL_PROFILE).createExtension(Arrays.asList(new String[] {IWorkItem.CREATION_DATE_PROPERTY, IWorkItem.SUMMARY_PROPERTY,IWorkItem.DESCRIPTION_PROPERTY})), null);

After the execution of these lines, result is showing values of all attribute of workitem(Full profile of workitem) instead of specific attribute(which i am expecting).  Anyone can suggest on this why it is showing complete values of workitem? and how to get only specific attributes of workitems instead of getting total workitem attributes




Comments
Ralph Schoon commented Sep 02 '13, 2:26 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Your code only finds and loads the work item. To get at the attribute you need to get the IAttribute first and then use .getValue(IAttribute) on the work item.

3 answers



permanent link
Ralph Schoon (57.1k23642) | answered Sep 02 '13, 2:24 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Please look at https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ and potentially at https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ and other related posts on that blog for code examples for common use cases.

Joshua http://www.joshuabambrick.com/rational/ has also published many examples. More links to examples can be found here too: https://rsjazz.wordpress.com/interesting-links/

Comments
Nilesh Patil commented Sep 02 '13, 2:35 a.m.

Hi Ralph
Thanks for the quick response.
But my concern is while I want to fetch only specific fields of workitem instead of complete attributes of workitem while loading(like in database we do select col_1,col_2 from table instated of select * from table). is it possible to fetch only specific attribute instead full profile workitem of workitem?


permanent link
Ralph Schoon (57.1k23642) | answered Sep 02 '13, 2:56 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You can create load profiles. Specific load profiles are used to limit the required data transfer.
The best place to look is IWorkItem for example look at how SMALL_PROFILE is defined:

    ItemProfile<IWorkItem> SMALL_PROFILE= ItemProfile.<IWorkItem>createProfile(ITEM_TYPE, AuditablesHelper.AUDITABLE_SMALL_PROFILE).createExtension(Arrays.asList(new String[] { PROJECT_AREA_PROPERTY, ID_PROPERTY, TYPE_PROPERTY, SUMMARY_PROPERTY, OWNER_PROPERTY, }));

I am not sure you can only load one attribute, I usually use the small profile and just add the one I want. I would try the expression above and only put in the one attribute.
I want into it e.g.

    ItemProfile<IWorkItem> SMALL_PROFILE= ItemProfile.<IWorkItem>createProfile(ITEM_TYPE, AuditablesHelper.AUDITABLE_SMALL_PROFILE).createExtension(Arrays.asList(new String[] { "MY_ATTRIBUTE_ID"}));

or use
 ItemProfile loadProfile = IWorkItem.SMALL_PROFILE.createExtension(              Arrays.asList(new String[] {  "MY_ATTRIBUTE_ID" }));

Maybe I don't understand your question correctly, but that should do the trick.
Please note, the work items are cached and I don't know if the small profile is always loaded by default. Work items are also objects which are mapped to the relational database table, so the comparison to SQL only carries so far.

Comments
Nilesh Patil commented Sep 16 '13, 12:26 a.m.

Hi Ralph,
   I have small doubt on above code. I have tried above code to get the specific field of workitem(Summary Description, owner, "MY_Custom_Attribute"). Its giving all values perfectly but the concern is that it's also giving value of other fields like attachment, other built in attribute, custom attributes which I don't want to fectch.

Could anyone tell why its fetching value of all attribute, instead of specific attribute? I want to fetch specific field of workitem


Ralph Schoon commented Sep 16 '13, 1:47 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

The SMALL_PROFILE is not empty and attachments are no attributes. However, that is the only mechanism I am aware of.


permanent link
Amaury Quintero (901017) | answered Sep 18 '15, 10:58 a.m.
 Hello

If you load one custom attributem, then all custom attributes are loaded, there is no way to do that. ItemProfile is no aware of single custom attributes.

Hope this help

Amaury

Comments
Ralph Schoon commented Sep 18 '15, 11:38 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Is is in disagreement with what I see in the item profiles themselves. They claim - and this is used in the production code as well - to be able to only force loading certain attributes. You can create item profiles for the attributes you want. I have also seen errors that indicate this actually works as described in https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ Item Profiles for Loading.

However, there is also caching implemented in the client and I don't know if you would sometimes get more than what you loaded.


1
Amaury Quintero commented Sep 22 '15, 3:44 a.m.

The "customAttributesProperty" is added to the custom profile every time you add a single custom attribute and from this very first moment you have access to all custom attributes, there is no way to have a custom profile with just one attribute. One thing is what in the code you can do and other what really happen behind the scenes.


Ralph Schoon commented Sep 22 '15, 4:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Interesting. Thanks for sharing.

Your answer


Register or to post your answer.