It's all about the answers!

Ask a question

How to get parent workitem attribute in custom editor presentation (dojo templated widget)


Denis Maliarevich (47712) | asked Mar 12 '14, 9:24 a.m.
I've created a custom widget for attribute presentation.
In web part (dojo templated widget) I need to get parent workitem attribute.
Is there a way to do it?

Process Enactment Workshop version 1.3 in Lab 5 says that:
"It is not possible to access the relationships of a work item, especially to other work items from the links
tab. It is possible to access work item attributes of type work item. This will return the work item handle
but will currently not allow to resolve the referenced work item."
So it's not clear whether it is possible or not.
Maybe it is possible in dojo templated widget via "this.workItem" or similar?

Currently I'm using RTC 4.0.4.
Maybe in newer versions of jazz there will be any support?

Accepted answer


permanent link
Sandeep Somavarapu (1011) | answered Apr 26 '14, 6:49 a.m.
JAZZ DEVELOPER
 Hi Denis,

You can get the links for a given link type from the working copy. You can also update (add or remove) links ofthe working copy. This is not straight forward and not suggested as this is internal and not a public API. This is subject to change.

To get links for a given link type:
this.workingCopy.getValue({path: ["linkTypes", linkType.id, "linkDTOs"], isSource: linkType.isSource, defaultValue: []});
where linkType.id is the identifier of the requested linkType. 
This will return an array of objects (if available).

To add a new link for a given link type:
Create an Object and set the following properties
newLink._isNew= true;
newLink.comment="" /*comment for the link*/
newLink.itemId="" /* item id of the linked item" - If the link type is an item link type
newLink.url= "" /* url of the linked item" - If the link type is an url link type

To the array, that you received using get, add this newly created object and set the array into working copy as follows:

 this.workingCopy.setValue({path: ["linkTypes", linkType.id, "linkDTOs"], isSource: linkType.isSource, value: array});

In the above code, you need to have the complete information about the link type you are going to access or update. For example, link type id, if the link type is item link type or url link type. If the link type is source or target.

In your case if you are adding a parent link then link type is 
parentLinkType= {id: "com.ibm.team.workitem.linktype.parentworkitem", isSource: false}
Parent link type is an item link type.

Note: We are working on providing a cleaner model and API (IWorkItemReferences) in Web for accessing and updating links of a work item. This will let you access, add and remove links very easily as it looks pretty similar to Java API. This will be available from 5.0.1.But there is no access to this model to the external consumers. We will be working on this which is not yet planned. 

Also please note that the above code and APIs are internal and subjected to change. So usage of these are at own risk. Hope this information helps you.

Thanks
Sandeep
Denis Maliarevich selected this answer as the correct answer

Comments
Denis Maliarevich commented Apr 28 '14, 4:49 a.m.

Thanks, Sandeep. So it's not a public API. We will think if it is acceptable for us to use it.


Denis Maliarevich commented Jun 12 '14, 4:49 a.m.

Hi, Sandeep,
I've tried your way to get the links - it works.
But my initial question had a second part: "In web part (dojo templated widget) I need to get parent workitem attribute. "
So now I have an object with some attributes of linked item. How can I get other attribues of this linked workitem? Particularly I need some custom attribute from linked wi.


Denis Maliarevich commented Jun 16 '14, 8:57 a.m.

Guys from IBM answered that "It seems   
that RTC does not provide the option to get a parent for given work    
item using dojo. There is also no build in attribute indicating parent 
for given work item. "
But I have managed to get the attribute via OSLC:


Denis Maliarevich commented Jun 16 '14, 8:57 a.m.

But I have managed to get the attribute via OSLC:
The required logic with the parent attribute is held in "_setValueFromParentAttr" function.
_parent: function() {
var args1 = {
    path: ["linkTypes", "com.ibm.team.workitem.linktype.parentworkitem", "linkDTOs"],
    isSource: false,
    defaultValue: []};
var list1 = this.workingCopy.getValue(args1);
var itemId="";
if (list1.length > 0) itemId=list1[0].itemId;
if (itemId!="") {
    var args2 = {
    url: "https://jazzSrv:9443/jazz/oslc/workitems/"+itemId+".json?oslc_cm.properties=rtc_cm:dc:title",
    handleAs: "json",
    load: dojo.hitch(this, this._setValueFromParentAttr),
    error: function(error) {
        console.log("error = ", error);
    }
    };
    dojo.xhrGet(args2);
}
}

One other answer



permanent link
Sandeep Somavarapu (1011) | answered Mar 13 '14, 5:44 p.m.
JAZZ DEVELOPER
 Denis, May I know how are you building this custom widget? Basically I would like to know the API you are using here. And what is the API you are using to get value for a work item attribute. 

Since you mentioned you are in web and building custom widget, I am guessing you are using WorkItemProxy for accessing Work Item data. Please let me know if this is correct.

Thanks
Sandeep

Comments
Denis Maliarevich commented Mar 17 '14, 6:25 a.m.

My widget is based on the article:
https://jazz.net/wiki/bin/view/Main/ContributingAttributePresentations
I use web UI, so the API is:
this.workingCopy.setValue({
    path: ["attributes", this.attributeId, "content"],
    attributeId: this.attributeId,
    value: newValue
});
// Getter
this.workingCopy.getValue({path: ["attributes", this.attributeId, "content"]});


Denis Maliarevich commented Mar 17 '14, 6:27 a.m.

So I need to get parent workitem attribute in web UI, using javascript or dojo.


Denis Maliarevich commented Apr 26 '14, 4:35 a.m.

Can anybody help me with solving this question?


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.