RTC - javascript - parent link required howto
Accepted answer
Hi Olivier,
The most compact way to retrieve links is to use the getValue() function on the proxy like so:
var childLinks = workItem.getProxy().getValue({
path : [ 'linkTypes', 'com.ibm.team.workitem.linktype.parentworkitem' ]
});
path : [ 'linkTypes', 'com.ibm.team.workitem.linktype.parentworkitem' ]
});
To actually create a link, the following code will do the trick (newProxy is the proxy for the new child item, and parentWorkItem is the actual parent work item, not its proxy):
var linkparam = {
isNew : true,
addLinkType : "com.ibm.team.workitem.linktype.parentworkitem",
addLinkIsSource : "false",
addLinkedProjectAreaItemId : parentWorkItem.getValue(WorkItemAttributes.PROJECT_AREA),
addLinkedItemId : parentWorkItem.getWorkItemItemId()
};
newProxy.addLinkTarget(linkparam);
var saveparam = {
self : this,
operationMsg : "Saving",
applyDelta : true,
onSuccess : function(param) {
console.log('Save Success');
parentWorkItem.getProxy().setHasNewLinksPending(true);
}
};
newProxy.storeWorkItem(saveparam);
Comments
One other answer
Yes, this is possible.
The officially supported Java Script API does not have the capability to detect links.
There is a work item proxy, that seems to allow finding links in JavaScript.
var proxy = workItem.getProxy();
This only works in the Web UI, is unsupported and should only be tried by really experienced JavaScript developers. There are posts in this forum using this.
Requiring a link to a work item can be achieved using a work item save advisor. Here an example of an advisor https://rsjazz.wordpress.com/2014/05/26/only-owner-can-close-workitem-advisor/
The blog has also examples around link APIs. E.g. https://rsjazz.wordpress.com/2012/11/27/resolve-parent-if-all-children-are-resolved-participant/