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. |
Accepted answer
![]() IWorkItemCommon workItemService= (IWorkItemCommon) getService(IWorkItemCommon.class);
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
|
4 other answers
![]() I'm developing a server-side plug-in to compare a custom attribute You can use (pseudo-code): IWorkItemCommon workItemService= saveParameter.getAuditableCommon().getPeer(IWorkItemCommon.class); IAttribute attribute= workItemService.findAttribute(projectArea, "your custom attribute id", monitor); Object value= workItem.getValue(attribute); -- Regards, Patrick RTC Work Item Component Lead |
![]()
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("#################### starts ######################"); 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(), "custom_attribute", monitor); IWorkItem workItem = (IWorkItem) auditable; System.out.println("value="+workItem.getValue(attribute)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
![]() Thanks for your comment. The ISaveParameter has two methods: getNewState() --> The work item with the current, modified values. getOldState() --> The original state as it exists in the repo. -- Regards, Patrick RTC Work Item Component Lead |
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.