It's all about the answers!

Ask a question

How to get a Field name in RTC WorkItem using Java


Chandan M B (521959) | asked Apr 07 '15, 11:34 p.m.
edited Apr 09 '15, 2:34 a.m. by Ralph Schoon (58.5k23642)
Assume in Summary Field, user enters some text,
I can fetch the entered value using getHTMLSummary()
But i need the field Name(Summary) in whcih field  it is entered.

Please let me know the code snippet for this.

Also, is there any documentation for server side plugin developement other than
Lab 1 to 6 PDF provided by IBM

Regards
Chandan

Accepted answer


permanent link
sam detweiler (12.4k6181201) | answered Apr 08 '15, 8:04 a.m.
 the accepted answer here provides a utility to dump the attribute values of workitems returned from a workitem query

https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes

this will show you the attribute names, and ID as well as value (for most attribute types)
Chandan M B selected this answer as the correct answer

Comments
Chandan M B commented Apr 08 '15, 11:17 p.m.

Hello Sam,
Thanks for the answer.

2 other answers



permanent link
Tiago Moura (8387) | answered Apr 08 '15, 12:16 a.m.
 Hi Chandan,

You can iterate over the custom attributes:

List<IAttributeHandle> customAttributes = workingCopy.getCustomAttributes();
for (IAttributeHandle iAttributeHandle : customAttributes) {
IAttribute attr = this.getItemFromHandle(IAttribute.class, iAttributeHandle, repositoryItemService);
System.out.println("@ATTR: " + attr.getIdentifier());
}
This two are good references about server side plugin developement:


Comments
Chandan M B commented Apr 08 '15, 12:24 a.m.

Hi,

IAttribute attr = this.getItemFromHandle(IAttribute.class, iAttributeHandle, itemService);
GetItemFromHandle i think is your custom function. I am getting an error in that line.

Please send me full snippet. Will be useful for me.


Chandan M B commented Apr 08 '15, 12:37 a.m.

That the Summary field is not a custom attribute.
Looping through the custome attribute is not needed i guess.
Can't we get the FieldName directly without looping

Regards
Chandan


Tiago Moura commented Apr 08 '15, 12:42 a.m.

 Oh! Sorry... here is the code from the getItemFromHandle:


repositoryService.fetchItem(handle, null)


Chandan M B commented Apr 08 '15, 3:02 a.m.

Actually,
I need basic IBM provided field names like Summary, Description
not customized fields.
I don't have a any customized field


permanent link
Ralph Schoon (58.5k23642) | answered Apr 09 '15, 2:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Internal attributes are treated similar to custom attributes. You can look up the ID of the attribute in the process configuration. There are also internal ID's for them which you can get using the code snippets above.

Also see https://rsjazz.wordpress.com/2015/02/27/a-rtc-workitem-command-line-version-2-2/ WorkItemTypeHelper class.
		List builtInAttributeHandles = getWorkItemCommon()
				.findBuiltInAttributes(projectArea, monitor);
		IFetchResult builtIn = fTeamRepository.itemManager()
				.fetchCompleteItemsPermissionAware(builtInAttributeHandles,
						IItemManager.REFRESH, monitor);

		List custAttributeHandles = workItemType
				.getCustomAttributes();

		IFetchResult custom = fTeamRepository.itemManager()
				.fetchCompleteItemsPermissionAware(custAttributeHandles,
						IItemManager.REFRESH, monitor);

		result.appendResultString("Attributes of Work Item type: "
				+ workItemType.getDisplayName() + " Type ID: "
				+ workItemType.getIdentifier());
		result.appendResultString("  Built In Attributes");
		result.appendResultString(printAttributesAndTypes(
				builtIn.getRetrievedItems(), monitor));
		result.appendResultString("  Custom Attributes");
		result.appendResultString(printAttributesAndTypes(
				custom.getRetrievedItems(), monitor));

.................

	private String printAttributesAndTypes(List items,
			IProgressMonitor monitor) {
		String message = "";
		message = message + "\tNumber of attributes: "
				+ new Integer(items.size()).toString() + "\n";
		for (@SuppressWarnings("rawtypes")
		Iterator iterator = items.iterator(); iterator.hasNext();) {
			Object object = iterator.next();
			if (object instanceof IAttribute) {
				IAttribute iAttribute = (IAttribute) object;
				message = message + "\t " + iAttribute.getDisplayName()
						+ " \tID: " + iAttribute.getIdentifier()
						+ " \tValueType: " + iAttribute.getAttributeType()
						+ "\n";
			}
		}
		return message;
	}

Your answer


Register or to post your answer.