It's all about the answers!

Ask a question

How to get the work item changed attribute and its new/old value for save work item operation follow up action?


Jia Jia Li (8057152192) | asked Jan 06 '16, 5:50 a.m.
I want to develop the follow-up action for the save work item operation to deal with the changed attribute and changed value.
Any one can help to tell me how to get the changed attribute and value for the operation?
I see the workshop can deal with the operation data to get old status and new status, but how to get the changed attribute and the changed attribute's old value and new value?

Object data = operation.getOperationData();
ISaveParameter saveParameter = null;
if (data instanceof ISaveParameter) {
            saveParameter = (ISaveParameter) data;
            IWorkItem newState = (IWorkItem) saveParameter.getNewState();
            Identifier<IState> newStateId = newState.getState2();
            Identifier<IState> oldStateId = null;
            IWorkItem oldState = (IWorkItem) saveParameter.getOldState();

3 answers



permanent link
Ralph Schoon (63.1k33646) | answered Jan 06 '16, 6:06 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jan 06 '16, 6:06 a.m.
The workshop gets the state from the "newState" and the state that the workItem in the oldState had and compares them. Similarly, you should be able to get the attribute value from the oldState and the newState and compare them.

permanent link
Jia Jia Li (8057152192) | answered Jan 06 '16, 11:00 p.m.
Hi Ralph, do you mean that using some code like "newState->getAttribute("summary") to get "summary" new value, and use "oldState->getAttribute("summary") to get "summary" old value? I think it is the way to get attribute new and old value.
But is there any way to get the changed attributes? When save work item, how could I know which attribute is changed? If I do not have this information, I guess I should traversal all work item attributes to compare the new and old value to judge if the attribute is changed, any good way to achieve this?

Comments
Ralph Schoon commented Jan 07 '16, 2:58 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

The syntax above is incorrect. https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ shows the correct syntax. E.g.

IAttribute attribute = workItemCommon.findAttribute(projectArea, "custom.attributeID",
                monitor);
if(attribute != null){
    String old = (String)oldState.getValue(attribute,monitor);
        String new = (String)newState.getValue(attribute,monitor);
} 

That would be my approach.


permanent link
Jia Jia Li (8057152192) | answered Jan 07 '16, 12:42 a.m.
I think my question now should be "how can I know the work item attribute has changed".....

Comments
Ralph Schoon commented Jan 07 '16, 1:41 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Compare the values of the getValue()?


sam detweiler commented Jan 07 '16, 8:16 a.m.

you could get the history entries which list the changed attributes, but its just as easy to run thru the list and compare..

from my dump workitem attributes sample code here
https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes

for (IAttribute ia : workItemCommon.findAttributes(projectArea,
                    monitor))

Your answer


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