How to get Child work items programatically

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

You can use IReference.resolve() method and then cast the Object into an IWorkItemHandle.
Best Regards,
Michele.
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);

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

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

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

Hi Michele
Thanks again..I have completed and its working.
It is ISaveParameter I used. May be spelling mistake.
Regards,
Radhika
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

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

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