It's all about the answers!

Ask a question

RTC - javascript - parent link required howto

Olivier ROSET (50221) | asked Jan 25 '19, 10:42 a.m.

Is it possible to have a parent type link be entered when saving a workitem in RTC?
I guess that goes through attribute conditions, but how do you access links to a workitem?

Accepted answer

permanent link
Davyd Norris (2.4k217) | answered Apr 29 '19, 2:51 a.m.
edited Apr 29 '19, 2:51 a.m.
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', '' ]

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 : "",
          addLinkIsSource : "false",
          addLinkedProjectAreaItemId : parentWorkItem.getValue(WorkItemAttributes.PROJECT_AREA),
          addLinkedItemId : parentWorkItem.getWorkItemItemId()

        var saveparam = {
          self : this,
          operationMsg : "Saving",
          applyDelta : true,
          onSuccess : function(param) {
            console.log('Save Success');
Olivier ROSET selected this answer as the correct answer

Olivier ROSET commented May 02 '19, 4:24 a.m. | edited May 02 '19, 4:56 a.m.
Thanks a lot for this answer.

My code will be more readable now. 

Davyd Norris commented May 02 '19, 4:52 a.m. | edited May 02 '19, 4:53 a.m.
BTW - the attribute in linkParam called addLinkIsSource is used to select which end of the relationship you are creating.

Each relationship type has an id - the Parent/Child relationship in this case has the id "", and then it has two ends. One end (the first in the relationship definition XML) is designated as the Source, and then IsSource allows you to declare which end you want to attach to the work item.

In this case we want the Child end, so addLinkIsSource is set to false

One other answer

permanent link
Ralph Schoon (63.3k33646) | answered Jan 28 '19, 2:29 a.m.

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

Olivier ROSET commented Jan 29 '19, 10:42 a.m. | edited Jan 29 '19, 10:43 a.m.


The workItem.getProxy() is the perfect solution.
I can read the workItem.getProxy()._valueSets._workItem._proxy.object.linkTypes array to check the links defined in the workItem.
It is possible to use the getProxy().storedObject to search for the workItem datas. 

Perfect. Thanks.

Ralph Schoon commented Jan 29 '19, 10:46 a.m.

Note that this is all not supported and does also not work in the RTC Eclipse client. 

Olivier ROSET commented Jun 05 '19, 8:17 a.m.
 Yes, and a strange behavior appears when we use workItem.getProxy() in, by example, ) attribute Validator javascript.
If we just do a call of this method, in the validate method of the validator code : 

validate: function(attributeId, workItem, configuration) {
        var proxy = workItem.getProxy();
        return new Status(Severity["ERROR"], "Feature sans EPIC parent !");

then the "return new Status() ..." is not interpreted.
If we remove the line : var proxy = workItem.getProxy(), everything works fine. 

Davyd Norris commented Jun 05 '19, 7:50 p.m.
I think you have something else going on there - calling getProxy() in that situation works fine for me.

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.