Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

RTC - javascript - parent link required howto

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?


0 votes


Accepted answer

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

2 votes

Comments
Thanks a lot for this answer.

My code will be more readable now. 

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

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/

0 votes

Comments

 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.

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

 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. 

I think you have something else going on there - calling getProxy() in that situation works fine for me.

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 12,029
× 235
× 152

Question asked: Jan 25 '19, 10:42 a.m.

Question was seen: 3,962 times

Last updated: Jun 05 '19, 7:50 p.m.

Confirmation Cancel Confirm