Update a Work Item Attribute using its Operation Participant
Hi,
I am trying to update a custom attribute of string type from a save triggered operation participant using java.
My code is as follows
saveParameter = (ISaveParameter) data;
IWorkItem newState = (IWorkItem) saveParameter.getNewState();
newState.setValue(attributeID, StringValue);
It doesn't give an exception or anything. It just doesn't work. Where am i going wrong here.
I am new at this and lost.
Please Help.
I am trying to update a custom attribute of string type from a save triggered operation participant using java.
My code is as follows
saveParameter = (ISaveParameter) data;
IWorkItem newState = (IWorkItem) saveParameter.getNewState();
newState.setValue(attributeID, StringValue);
It doesn't give an exception or anything. It just doesn't work. Where am i going wrong here.
I am new at this and lost.
Please Help.
6 answers
Hi,
why do you use Client API on OperationAdvisor?
I suggest you to use server side API. In order to save a work-item you can use IWorkItemServer instead of IWorkItemClient. Methods are quite similar. You are already logged in as you run Advisor, you don't need to re-login.
Michele.
Could you please let me know the solution?
I did not find any solution for this since some weeks.
I have to use com.ibm.team.repository.client.ITeamRepository as well in my current development Item.
Thanks in Advance
Regards,
Radhika B
why do you use Client API on OperationAdvisor?
I suggest you to use server side API. In order to save a work-item you can use IWorkItemServer instead of IWorkItemClient. Methods are quite similar. You are already logged in as you run Advisor, you don't need to re-login.
Michele.
Hi Arun,API in your OperationParticipant plug-in. I am also trying to use client libraries in my OperationAdvisor but when I import client related libraries, the plug-in is not deployed on the server.
I think you have used com.ibm.team.workitem.client.IWorkItemClient
Could you please let me know the solution?
I did not find any solution for this since some weeks.
I have to use com.ibm.team.repository.client.ITeamRepository as well in my current development Item.
Thanks in Advance
Regards,
Radhika B
the IWorkItem u have in the OperationAdvisor is a READ ONLY instance..
you must get the WorkingCopy to modify it..
in my OperationAdvisor , I assume something similar is done in a Participant.
you should always assume it is read only unless YOU just created the workitem.
---- edit.. you are in an OperationParticipant, and so shouldn't have a data overlay problem..
Sam
you must get the WorkingCopy to modify it..
in my OperationAdvisor , I assume something similar is done in a Participant.
// reference the right object type (cast)
IWorkItem workItem = (IWorkItem) auditable;
IWorkItem rr = (IWorkItem)workItem.getWorkingCopy();
you should always assume it is read only unless YOU just created the workitem.
---- edit.. you are in an OperationParticipant, and so shouldn't have a data overlay problem..
Sam
Hi Arun,
I think you have used com.ibm.team.workitem.client.IWorkItemClient API in your OperationParticipant plug-in. I am also trying to use client libraries in my OperationAdvisor but when I import client related libraries, the plug-in is not deployed on the server.
Could you please let me know the solution?
I did not find any solution for this since some weeks.
I have to use com.ibm.team.repository.client.ITeamRepository as well in my current development Item.
Thanks in Advance
Regards,
Radhika B
I think you have used com.ibm.team.workitem.client.IWorkItemClient API in your OperationParticipant plug-in. I am also trying to use client libraries in my OperationAdvisor but when I import client related libraries, the plug-in is not deployed on the server.
Could you please let me know the solution?
I did not find any solution for this since some weeks.
I have to use com.ibm.team.repository.client.ITeamRepository as well in my current development Item.
Thanks in Advance
Regards,
Radhika B
That is indeed correct for getting the work item client, the code to log in to the repository is
Where repositoryURI is the address of your jazz repository, for example: https://jazz705.hursley.ibm.com:9443/ccm
and then put your user name and password in, the login handler is an internal class
Then
ITeamRepository teamRepository= TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI);
teamRepository.registerLoginHandler(new LoginHandler(userId, password));
teamRepository.login(null);
Where repositoryURI is the address of your jazz repository, for example: https://jazz705.hursley.ibm.com:9443/ccm
and then put your user name and password in, the login handler is an internal class
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;
}
}
Then
IWorkItemClient workItemClient= (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);will get the work item client for you.
Hi,
Thank you for your reply. It was very useful. However could you please tell me how to getworkItemClient .
I am trying to get it using
If this is correct, how do i get the ITeamRepositoryrepo .
Thanks
Arun
Thank you for your reply. It was very useful. However could you please tell me how to get
I am trying to get it using
IWorkItemClient wiclient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
If this is correct, how do i get the ITeamRepository
Thanks
Arun
The code below should edit a work item for you, you will need to change the id of the work item you are getting, change the identifier of the attribute you are getting and put a value in.
Hope this helps.
Hope this helps.
ItemProfile<IWorkItem> profile = IWorkItem.DEFAULT_PROFILE;
IWorkItem workItem = workItemClient.findWorkItemById(2000,profile, null);
if (workItem == null) {
System.out.println("Work Item not found.");
return false;
}
IWorkItemHandle handle = (IWorkItemHandle) workItem.getItemHandle();
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
wcm.connect(handle, IWorkItem.FULL_PROFILE, null);
WorkItemWorkingCopy wc = wcm.getWorkingCopy(handle);
IWorkItem copiedWorkItem = wc.getWorkItem();
try {
IAttribute customAttribute = workItemClient.findAttribute(projectArea, "attributeIdentifier", null);
copiedWorkItem.setValue(customAttribute, "yourValue");
wc.save(null);