Changing value of read-only attribute using plain java api
Hi, In RTC, is it possible to change the selected value of a read-only attribute of a specific workitem/s using plain java api, specifically for the Priority attribute? I tried to do that but after saving the working copy, the Priority value of the workitem didn’t change when I checked it in the web rtc. |
Accepted answer
Ralph Schoon (63.6k●3●36●46)
| answered Sep 02 '14, 3:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
In 5.0 at least,you can not modify the work item attribute if it is set to read only. You can modify it if it is only read only in the editor presentations.
I doubt you can do it if prevent editing is set. Try it yourself. Here is some sample code: /******************************************************************************* * Licensed Materials - Property of IBM * (c) Copyright IBM Corporation 2014. All Rights Reserved. * * Note to U.S. Government Users Restricted Rights: Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *******************************************************************************/ package com.ibm.js.team.workitem.automation.examples; import java.net.URI; import org.eclipse.core.runtime.IProgressMonitor; import com.ibm.team.foundation.common.text.XMLString; import com.ibm.team.process.client.IProcessClientService; import com.ibm.team.process.common.IProjectArea; import com.ibm.team.repository.client.ITeamRepository; import com.ibm.team.repository.client.ITeamRepository.ILoginHandler; import com.ibm.team.repository.client.ITeamRepository.ILoginHandler.ILoginInfo; import com.ibm.team.repository.client.TeamPlatform; import com.ibm.team.repository.common.TeamRepositoryException; import com.ibm.team.workitem.client.IWorkItemClient; import com.ibm.team.workitem.client.WorkItemOperation; import com.ibm.team.workitem.client.WorkItemWorkingCopy; import com.ibm.team.workitem.common.model.IAttribute; import com.ibm.team.workitem.common.model.IWorkItem; import com.ibm.team.workitem.common.model.IWorkItemReferences; /** * Example code, see * https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation. */ public class ModifyWorkItemAttributeOperation { private static class LoginHandler implements ILoginHandler, ILoginInfo { private String fUserId; private String fPassword; private LoginHandler(String userId, String password) { fUserId = userId; fPassword = password; } public String getUserId() { return fUserId; } public String getPassword() { return fPassword; } public ILoginInfo challenge(ITeamRepository repository) { return this; } } private static class WorkItemSummaryModification extends WorkItemOperation { private String fAttributeId; private String fAttributeValueString; public WorkItemSummaryModification(String attributeId, String attributeValueString) { super("Modifying Work Item", IWorkItem.FULL_PROFILE); fAttributeId = attributeId; fAttributeValueString = attributeValueString; } @Override protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException { IWorkItem workItem = workingCopy.getWorkItem(); ITeamRepository teamRepository = (ITeamRepository) workItem .getOrigin(); IWorkItemClient workItemClient = (IWorkItemClient) teamRepository .getClientLibrary(IWorkItemClient.class); // workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary)); if (null != fAttributeId) { IAttribute customString = workItemClient.findAttribute( workItem.getProjectArea(), fAttributeId, monitor); if (workItem.hasCustomAttribute(customString)) workItem.setValue(customString, fAttributeValueString); } } } public static void main(String[] args) { boolean result; TeamPlatform.startup(); try { result = run(args); } catch (TeamRepositoryException x) { x.printStackTrace(); result = false; } finally { TeamPlatform.shutdown(); } if (!result) System.exit(1); } private static boolean run(String[] args) throws TeamRepositoryException { if (args.length != 7) { System.out .println("Usage: ModifyWorkItem Lyka Bernardo selected this answer as the correct answer
Comments
Lyka Bernardo
commented Sep 02 '14, 3:57 a.m.
Hi Ralph,
Yes I tried updating it using the codes I found here in jazz. I can't update it when the Prevent Editing precondition is enabled. I just disabled the precondition and it was updated.
Thanks to you and Susan for your answers. :) I checked with 4.0.3 and the plain Java client libraries did not work there either. Please note, a calculated value provider however, was able to change the attribute even if it was read only. An external client wasn't.
|
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.
Comments
If the entire attribute is r/o (like via the Operational Behavior advisor Read Only for type and state) then I don't believe you can.
If the attribute is shown as R/O just in the editor but the attribute itself is not R/O at that time (state/type/etc), then you should be able to.
Hello Susan,
How about if the precondition is Prevent Editing?