Get a custom attribute value from a server side extension
Hi
I am trying to extend my RTC with an OperationAdvisor .
My concern is to force user to fill a given custom attribute when the state is "Resolved" (close state) and the Resolution value is "Fixed Upstream"
1. is there a way to compare state and resolution to real string values ("Resolved" and "Fixed Upstream") and not to their identifier (state.s5 and resolution.r1)
2. how can I get a custom field value (check if not null) from server side.
I saw fews samples but I did not understand how to access workitem.attribute method from server side.
I appreciate a detailed example
Thx
Roger
Accepted answer
You can do this without an extension.
Go into the Process Configuration for your project, and select Team Configuration -> Operation Behavior, and then scroll to the bottom of the list of operations to Work Items -> Save Work Item (server). For that particular operation, select the Required Properties precondition, and set the fields that you want to be mandatory for users to fill in when the state and resolution are set to particular values (in your case, Resolved and Fixed Upstream).
3 other answers
there is no direct way to use the state or resolution labels. they are contained in a different table than the IDs..
to access the value of a custom attribute on the server (or anywhere), use its ID as a string "com.xx.foo.bar" (or whatever it is in the process XML.
the third post here shows how to decode the states.
here is code I used in one plugin to check for "Resolved" state
<code>
private static String ResolvedState = "resolved";
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))
</code>
to access the value of a custom attribute on the server (or anywhere), use its ID as a string "com.xx.foo.bar" (or whatever it is in the process XML.
the third post here shows how to decode the states.
here is code I used in one plugin to check for "Resolved" state
<code>
private static String ResolvedState = "resolved";
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))
</code>