Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Get custom attribute key and value in Server-Side plugin

Hello~

I'm developing a server-side plug-in to compare a custom attribute value of my own workitem between previous and current.

My code is like below.
I can successfully see some summary data.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Object data= operation.getOperationData();

if (data instanceof ISaveParameter) {
IAuditable auditable = ((ISaveParameter) data).getNewState();

if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
System.out.println("Summary : " + workItem.getHTMLSummary());
// I need to get custom attribute key and value to compare previous and current.
...
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Is there any example code to get custom attribute of my workitem?
Any help will be appriciated.

0 votes


Accepted answer

Permanent link
IWorkItemCommon workItemService= (IWorkItemCommon) getService(IWorkItemCommon.class);
// You have to add this class in plugin.xml
IAttribute attribute= workItemService.findAttribute(operation.getProcessArea().getProjectArea(), "ur_attr_id", monitor);
String currentWI_TaskType = sourceworkItem.getValue(attribute).toString();   
// return object type data maybe you want to convert
plugin.xml (this is mine)

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="com.ibm.team.process.service.operationAdvisors">
      <operationAdvisor
            class="jazzdevapprovaladvisor.JazzDevApprovalSave"
            id="JazzDevApprovalAdvisor"
            name="JazzDev Approval Advisor"
            operationId="com.ibm.team.workitem.operation.workItemSave">
            <extensionService componentId="JazzDevApprovalAdvisor" 
            	implementationClass="jazzdevapprovaladvisor.JazzDevApprovalSave">
            	<prerequisites> 
					<requiredService interface="com.ibm.team.repository.service.IRepositoryItemService" />
					<optionalservice interface="com.ibm.team.repository.common.service.IContributorService"/> 
					<optionalservice interface="com.ibm.team.workitem.common.IWorkItemCommon"/>   
				</prerequisites>  
			 </extensionService>
      </operationAdvisor>
   </extension>
</plugin>
Ralph Schoon selected this answer as the correct answer

0 votes


4 other answers

Permanent link
I'm developing a server-side plug-in to compare a custom attribute
value of my own workitem between previous and current.

My code is like below.
I can successfully see some summary data.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Object data= operation.getOperationData();

if (data instanceof ISaveParameter) {
IAuditable auditable = ((ISaveParameter) data).getNewState();

if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
System.out.println(&quot;Summary : &quot; +
workItem.getHTMLSummary());
// I need to get custom attribute key and value to compare previous
and current.
...
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Is there any example code to get custom attribute of my workitem?
Any help will be appriciated.


You can use (pseudo-code):

IWorkItemCommon workItemService=
saveParameter.getAuditableCommon().getPeer(IWorkItemCommon.class);

IAttribute attribute= workItemService.findAttribute(projectArea, &quot;your
custom attribute id&quot;, monitor);

Object value= workItem.getValue(attribute);

--
Regards,
Patrick
RTC Work Item Component Lead

0 votes


Permanent link
Thanks for your comment.

I'm able to get current value of custom attribute.

However I need to get previous data to compare with current value.

How can I do this?

Thanks in advance.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public class OperationAdvisor extends AbstractService implements IOperationAdvisor {

public void run(AdvisableOperation operation,
IProcessConfigurationElement advisorConfiguration,
IAdvisorInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {

try {

System.out.println(&quot;#################### starts ######################&quot;);


Object data= operation.getOperationData();

if (data instanceof ISaveParameter) {
IAuditable auditable = ((ISaveParameter) data).getNewState();

IWorkItemCommon workItemService = ((ISaveParameter)data).getSaveOperationParameter().getAuditableCommon().getPeer(IWorkItemCommon.class);


IAttribute attribute= workItemService.findAttribute(operation.getProcessArea().getProjectArea(), &quot;custom_attribute&quot;, monitor);

IWorkItem workItem = (IWorkItem) auditable;
System.out.println(&quot;value=&quot;+workItem.getValue(attribute));

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 votes


Permanent link
Thanks for your comment.

I'm able to get current value of custom attribute.

However I need to get previous data to compare with current value.

How can I do this?

The ISaveParameter has two methods:

getNewState() --&gt; The work item with the current, modified values.
getOldState() --&gt; The original state as it exists in the repo.

--
Regards,
Patrick
RTC Work Item Component Lead

0 votes


Permanent link
I figured it out.
Thanks for your support.

0 votes

Comments

"getPeer" is an deprecated method . What is the equivalent method ?

IWorkItemCommon workItemService = ((ISaveParameter)data).getSaveOperationParameter().getAuditableCommon().getPeer(IWorkItemCommon.class);

extend the Abstract class and then you can use the getservice() method to get the service of required class

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,952

Question asked: Oct 25 '10, 5:18 a.m.

Question was seen: 7,741 times

Last updated: Sep 11 '14, 2:46 a.m.

Confirmation Cancel Confirm