It's all about the answers!

Ask a question

RTC - javascript - parent link required howto


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

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.2k217) | 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', '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);
Olivier ROSET selected this answer as the correct answer

Comments
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 "com.ibm.team.workitem.linktype.parentworkitem", 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.1k33645) | answered Jan 28 '19, 2:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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/


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

 Thanks.

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.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.