(Server Side RTC) How to fetch the Previous state and Current state of the Workitem Workflow ?
2 answers
current state is easy.
what does previous mean? is your code in an advisor or participant extension?
is so, then the info is passed in to the call to the extension.
the about to be state is
IAuditable auditable = ((ISaveParameter) data).getNewState();
the current (or old) state is
IAuditable auditable = ((ISaveParameter) data).getOldState();
after that the info is stored in the history.
what does previous mean? is your code in an advisor or participant extension?
is so, then the info is passed in to the call to the extension.
the about to be state is
IAuditable auditable = ((ISaveParameter) data).getNewState();
the current (or old) state is
IAuditable auditable = ((ISaveParameter) data).getOldState();
after that the info is stored in the history.
Ok, the OldState should say 'InProgress',
and NewState should say 'Closed'
my advisor checks for workitems transitioning to 'Resolved' state..
String ResolvedState="resolved";
if (data instanceof ISaveParameter) {
// get the affected objects planned new state (cause this is a SAVE operation)
IAuditable auditable = ((ISaveParameter) data).getNewState();
// if this is a workitem
if (auditable instanceof IWorkItem)
{
// get the worker objects
IAuditableCommon iac = ((ISaveParameter) data).getSaveOperationParameter().getAuditableCommon();
WorkflowManager wfm = new WorkflowManager(iac);
// reference the right object type (cast)
IWorkItem workItem = (IWorkItem) auditable;
// get the workflow this workitem is in, so we can get the labels of the states
IWorkflowInfo x =wfm.getWorkflowInfo(workItem, monitor);
if(Debug) System.out.println("the workitem state is "+ workItem.getState2().getStringIdentifier()+ "=" +x.getStateName(workItem.getState2()) );
// if this workitem is going into resolved state (we accessed 'proposed new' state above
if(x.getStateName(workItem.getState2()).equalsIgnoreCase(ResolvedState))
and NewState should say 'Closed'
my advisor checks for workitems transitioning to 'Resolved' state..
String ResolvedState="resolved";
if (data instanceof ISaveParameter) {
// get the affected objects planned new state (cause this is a SAVE operation)
IAuditable auditable = ((ISaveParameter) data).getNewState();
// if this is a workitem
if (auditable instanceof IWorkItem)
{
// get the worker objects
IAuditableCommon iac = ((ISaveParameter) data).getSaveOperationParameter().getAuditableCommon();
WorkflowManager wfm = new WorkflowManager(iac);
// reference the right object type (cast)
IWorkItem workItem = (IWorkItem) auditable;
// get the workflow this workitem is in, so we can get the labels of the states
IWorkflowInfo x =wfm.getWorkflowInfo(workItem, monitor);
if(Debug) System.out.println("the workitem state is "+ workItem.getState2().getStringIdentifier()+ "=" +x.getStateName(workItem.getState2()) );
// if this workitem is going into resolved state (we accessed 'proposed new' state above
if(x.getStateName(workItem.getState2()).equalsIgnoreCase(ResolvedState))
Comments
Thanks Sam. But the above code will provide only the current state , not the Previous state right ? Correct me if iam wromg
Below is my code is similar to yours -----
Identifier<IState> state = sourceworkItem.getState2();
IWorkflowInfo workflowInfo = workItemServer.findWorkflowInfo(sourceworkItem, monitor);
System.
out.println (" Work Item Name :" + workflowInfo.getStateName(state).toString());
correct, my code only looks at the new state, I don't care about old..
but YOU DO.. so you could change my code a little to ge the PRIOR (aka old) state too