Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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.

0 votes



6 answers

Permanent link
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.

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

0 votes


Permanent link
Hi,

Thank you for your reply. It was very useful. However could you please tell me how to get workItemClient.

I am trying to get it using

IWorkItemClient wiclient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);


If this is correct, how do i get the ITeamRepository repo.


Thanks
Arun

0 votes


Permanent link
That is indeed correct for getting the work item client, the code to log in to the repository is
 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.

0 votes


Permanent link
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

0 votes


Permanent link
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.

// 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

0 votes


Permanent link
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.

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

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937

Question asked: Sep 14 '11, 10:29 a.m.

Question was seen: 8,561 times

Last updated: Sep 14 '11, 10:29 a.m.

Confirmation Cancel Confirm