It's all about the answers!

Ask a question

How to get Child work items programatically


radhika bandari (10675) | asked Oct 21 '11, 3:22 a.m.
Hi,

My requirement is to set values to some custom attributes of child work item of a particular work item before it gets saved. I am implementing an IOperationAdvisor.
I am able to get child references, but how to get exactly child work items, so that I can set custom attribute values.

if (data instanceof ISaveParameter) {
IAuditable auditable = ((ISaveParameter) data).getNewState();
if (auditable instanceof IWorkItem) {
IWorkItem parentworkItem= (IWorkItem) auditable;

IWorkItemReferences references = service.resolveWorkItemReferences(parentworkItem, null);

List<IReference> listChildReferences = references.getReferences(WorkItemEndPoints.CHILD_WORK_ITEMS);

IReference childReference = listChildReferences.get(0);

9 answers



permanent link
Michele Pegoraro (1.8k14118103) | answered Oct 21 '11, 3:50 a.m.
You can use IReference.resolve() method and then cast the Object into an IWorkItemHandle.

Best Regards,
Michele.

Hi,

My requirement is to set values to some custom attributes of child work item of a particular work item before it gets saved. I am implementing an IOperationAdvisor.
I am able to get child references, but how to get exactly child work items, so that I can set custom attribute values.

if (data instanceof ISaveParameter) {
IAuditable auditable = ((ISaveParameter) data).getNewState();
if (auditable instanceof IWorkItem) {
IWorkItem parentworkItem= (IWorkItem) auditable;

IWorkItemReferences references = service.resolveWorkItemReferences(parentworkItem, null);

List<IReference> listChildReferences = references.getReferences(WorkItemEndPoints.CHILD_WORK_ITEMS);

IReference childReference = listChildReferences.get(0);

permanent link
radhika bandari (10675) | answered Oct 21 '11, 6:38 a.m.
Hi,
Thank you for fast reply Michele. Its working. I am able get workitem.
I am very new to RTC. I need to set values to some custom attributes of childworkitem. i used below code.

if (!childWorkItem.isWorkingCopy()) {
childWorkItem = (IWorkItem) childWorkItem.getWorkingCopy();
}
List <IAttributeHandle> allCustomAttributes=parentworkItem.getCustomAttributes();
for (IAttributeHandle attributeHandle : allCustomAttributes){
customAttribute=service.getAuditableCommon().resolveAuditable(attributeHandle, IAttribute.FULL_PROFILE, monitor);
String attributeName=customAttribute.getDisplayName();
if(attributeName.startsWith("Asset Name")){
childWorkItem.setValue(customAttribute, customAttribute.getValue(service.getAuditableCommon(), sourceworkItem, null));

}
But the value is not set. Can you suggest me how to set.

You can use IReference.resolve() method and then cast the Object into an IWorkItemHandle.

Best Regards,
Michele.

Hi,

My requirement is to set values to some custom attributes of child work item of a particular work item before it gets saved. I am implementing an IOperationAdvisor.
I am able to get child references, but how to get exactly child work items, so that I can set custom attribute values.

if (data instanceof ISaveParameter) {
IAuditable auditable = ((ISaveParameter) data).getNewState();
if (auditable instanceof IWorkItem) {
IWorkItem parentworkItem= (IWorkItem) auditable;

IWorkItemReferences references = service.resolveWorkItemReferences(parentworkItem, null);

List<IReference> listChildReferences = references.getReferences(WorkItemEndPoints.CHILD_WORK_ITEMS);

IReference childReference = listChildReferences.get(0);

permanent link
Michele Pegoraro (1.8k14118103) | answered Oct 21 '11, 9:34 a.m.
You have to save it in order to see it. You can use IWorkItemServer.saveWorkItem2 on server side.

Best regards,
Michele.

permanent link
radhika bandari (10675) | answered Nov 04 '11, 6:27 a.m.
You have to save it in order to see it. You can use IWorkItemServer.saveWorkItem2 on server side.

Best regards,
Michele.


Hi Michele,

Its working. Thank you..
Is it possible to check the Parent Reference (Just created through Eclipse client, not saved in the server) of a workitem before saving it in to server programmatically. should not allow workitem to be saved in to server with out Parent Reference created.
I am able to read customAttributes before saving in to server but unable to read References. How can we achieve this?

Thanks in advance
Radhika Bandari

permanent link
Michele Pegoraro (1.8k14118103) | answered Nov 05 '11, 4:18 a.m.
You can get new references from an ISaveOperation object using getNewReferences. You can also get them using ILinkService and ILinkServiceLibrary, searching for links using one of the findLinks methods.

Best Regards,
Michele.



Hi Michele,

Its working. Thank you..
Is it possible to check the Parent Reference (Just created through Eclipse client, not saved in the server) of a workitem before saving it in to server programmatically. should not allow workitem to be saved in to server with out Parent Reference created.
I am able to read customAttributes before saving in to server but unable to read References. How can we achieve this?

Thanks in advance
Radhika Bandari

permanent link
radhika bandari (10675) | answered Nov 07 '11, 6:50 a.m.
Hi Michele

Thanks again..I have completed and its working.
It is ISaveParameter I used. May be spelling mistake.

Regards,
Radhika

You can get new references from an ISaveOperation object using getNewReferences. You can also get them using ILinkService and ILinkServiceLibrary, searching for links using one of the findLinks methods.

Best Regards,
Michele.



Hi Michele,

Its working. Thank you..
Is it possible to check the Parent Reference (Just created through Eclipse client, not saved in the server) of a workitem before saving it in to server programmatically. should not allow workitem to be saved in to server with out Parent Reference created.
I am able to read customAttributes before saving in to server but unable to read References. How can we achieve this?

Thanks in advance
Radhika Bandari

permanent link
radhika bandari (10675) | answered Nov 09 '11, 12:52 a.m.
Hi Michele,

I have one requirement. workitem attribute "Filed Against" default value will be shown as

"Unassigned". I need to change its value to one of the Project Areas(Filed Against dropdown already

contains Project areas) upon saving the workitem programatically.
I tried getting its value using below code.

Object data= operation.getOperationData();
IProcessArea processArea = operation.getProcessArea();
IProjectArea projectArea = (IProjectArea) processArea;
ITeamRepository teamRepository = (ITeamRepository)projectArea.getOrigin();

IItemManager itm = teamRepository.itemManager();
//get existing category value.
ICategory category = (ICategory) itm.fetchCompleteItem(parentWorkItem.getCategory(),

IItemManager.DEFAULT, monitor);
System.out.println("This is category: " + category.getName());
Once i invoke the plugin it is

showing this message
State
CopyAttributeValuesToChildWI (Operation Advisor) completed successfully.

Am I doing in a right way? Could you please suggest me on how to do this.

Regards,
Radhika

permanent link
radhika bandari (10675) | answered Nov 09 '11, 1:16 a.m.
Hi Michele,

This is regarding the same FiledAgainst requirement.
Is it possible to do by editing any configurations like Process configuration such that "FiledAgainst" dropdown shows the ProjectArea Name as its selected value? Project area to which the workitem belongs to.

Appreciate your suggession Michele.


Thank you,
Radhika

permanent link
sam detweiler (12.5k6195201) | answered Nov 09 '11, 3:23 p.m.
see my post on how to resolve the workitems on the end of links in an OperationAdvisor

https://jazz.net/forums/viewtopic.php?&p=68473&sid=fdb2e0ffea8ac7d77ec3a7b0cf34a16a
see last post

Sam

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.