It's all about the answers!

Ask a question

Programatically making an attribute of workitem Read-only


Ankur Sharma (151194) | 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.)

Thanks
-Ankur

One answer



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

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

https://jazz.net/wiki/bin/view/Main/TeamProcessDeveloperGuide#Adding_New_Operation_Advisors

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))
return;

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);
info.setProblemObject(workItem.getItemHandle());
collector.addInfo(info);
return;
}
}
}


Thanks,

Simon

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.