It's all about the answers!

Ask a question

Programatically making an attribute of workitem Read-only

Ankur Sharma (15194) | asked Jul 16 '09, 6:37 a.m.
Hi all

I want that one of the attributes of workitem should be editable only when the workitem is in New and In Progress state. Once it goes to Resolve state it should no longer be editable. If someone wants to edit it he has to come back to In Progress or New state. How this can be made possible ? ( I want to do this through a precondition. Precondition will check while changing the state of workitem to Resolve state, that if that attribute has any value defined in it. If not then it will stop the save action. If value is defined then it will make the field non-editable.)


One answer

permanent link
Simon Fisher (1631710) | answered Jul 17 '09, 12:37 p.m.

Look at this wiki page for info on adding new preconditions.

The following code should get you started with the problem you described above. Note the stringIdentifier of the work item's state may not be as I have put here - you should look this up in your process configuration.

public void run(AdvisableOperation operation,
IProcessConfigurationElement advisorConfiguration,
IAdvisorInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {

Object data= operation.getOperationData();
if (!(data instanceof ISaveParameter))

ISaveParameter saveParameter= (ISaveParameter) data;
if (saveParameter.getNewState() instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem)saveParameter.getNewState();
if (workItem.getState2().getStringIdentifier().equals("new") || workItem.getState2().getStringIdentifier().equals("in_progress")) {
IWorkItem oldWorkItem = (IWorkItem)saveParameter.getOldState();
// use one of the IWorkItem.get...() methods to compare
// the values of the attributes in new and old states
// if it is different, do this:
String summary = "Attribute not editable";
String description = "This attribute is not editable unless the work item is in state 'New' or 'In Progress'";
IAdvisorInfo info= collector.createProblemInfo(summary, description, ID);



Your answer

Register or to post your answer.