How to get the new state name in operation advisor on performing save operation?
The following code is being used to get the new and old state name.
if (auditable instanceof IWorkItem) {
IWorkItem wi = (IWorkItem) auditable;
Identifier<IState> newStateId = wi.getState2();
Identifier<IState> oldStateId = null;
IWorkItem oldState = (IWorkItem) ((ISaveParameter) data).getOldState();
if (oldState != null) {// New work item check.
oldStateId = oldState.getState2();
}
if ((newStateId != null) && !(newStateId.equals(oldStateId))) {
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IWorkflowInfo workflowInfo = workItemServer.findWorkflowInfo(wi, monitor);
newStateID=workflowInfo.getStateName(newStateId);
if (oldState != null){
oldStateID=workflowInfo.getStateName(oldStateId);
}
3 answers
Comments
Some more information on states API.
You have to look it up in the workflow info. See http://rsjazz.wordpress.com/2012/11/26/manipulating-work-item-states/ for details.
I am not sure if it would help to resolve the work item and look at the state that is available after the save. You could try that.
You would see the new state in an advisor or participant that is run as a result of the save you just did. You can pass information between the operational behaviors using save3. See http://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ for some hints no that.
consider if the old state is validation and new state will be acknowledged.
The point is even before the save operation is complete(say,interrupted by an error message on save), I am getting the new state name as acknowledged.
I fail to see the problem. It is a good thing that you see the target state, because you can now detect that a state change is happening and where it is going. If you wanted, you could prevent that from happening. This is actually a key capability for a majority of advisors and participants.
If you are looking for the state before the save finishes you can use the old state which provides the value of the work item before the save is finally committed.
Also be aware that the newState data will only be committed if all advisors and participants agree.
I am checking both old and new state to send the notifications,ie if the old state is validation and new state is acknowledged only then it has to send a mail to the required user.If an error message appear in between disturbing the save operation,the new state value is acknowledged and sends mail. And even after the successful save operation also the new state name is acknowledged,so the mail is being sent twice.I am trying to restrict the mail sending onlu once.What is the possible way to avoid repetition of sending mails?
If I would use a participant I would only trigger on the state change like done here https://jazz.net/library/article/1000 and I would put the participant at the end of the participants list in the process configuration.