It's all about the answers!

Ask a question

How to get certain values in an Operation Advisor?


Susan Hanson (1.6k2186193) | asked Jan 20 '14, 1:45 a.m.
This is probably pretty elementary, but ...
I am coding up an Operation Advisor to throw an error if the user attempts to move a work item into "In Progress" state when one of my custom attributes contains a certain value.

I have done a sample OperationAdvisor, but I am having a few issues with this one.
1) How can I get the value of a custom attribute?  I can do this in plain java but for that, I use a workItemClient.findAttribute() method, but I'm not sure how to get a workItemClient from within an Operation Advisor.  Or perhaps there is an easier way since I have the IWorkItem itself.

2) In the sample, the saveParameter there is a getOldState() method and getNewState() method.  Can someone help with what those would return?  My sample does getNewState() which then is cast to an IWorkItem. Does this mean these would be the values *IF* the save completed?  I don't think so based on some other things that I have read since the save hasn't occurred yet.  Or are these the IWorkItems with the old attribute values and the new attribute values that were selected?

Thanks
Susan

Comments
sam detweiler commented Jan 20 '14, 5:45 a.m. | edited Jan 20 '14, 5:49 a.m.

Yes oldstate and newstate are the complete workitem..

before and the target after the save. you cannot change newstate

workitem.getvalue('id')is how to extract data from a field. just like in the client code for custom attributes u use the complete id.


Susan Hanson commented Jan 20 '14, 6:01 a.m.

Thanks Sam.  I initially had wanted to try workitem.getValue('id') but I only see getValue(IAttribute attribute) as a valid API.

Susan

2 answers



permanent link
sam detweiler (12.5k6185201) | answered Jan 20 '14, 6:12 a.m.
yeh, sorry.. morning
IWorkItemCommon workItemCommon= getService(IWorkItemCommon.class);
IAttribute attribute= workItemCommon.findAttribute(workItem.getProjectArea(), 'id', monitor);

u need to list IWorkitemCommon as a dependency in your plugin.xml

permanent link
Susan Hanson (1.6k2186193) | answered Jan 21 '14, 3:19 a.m.
Sam, you were right-on:
IWorkItemCommon workItemCommon= getService(IWorkItemCommon.class);
IAttribute attribute= workItemCommon.findAttribute(workItem.getProjectArea(), 'id', monitor);

Your answer


Register or to post your answer.