It's all about the answers!

Ask a question

In a work item attribute validator customization, how can I specify a value is invalid if they have not linked a Parent?


Donna Thomas (14122649) | asked Nov 09 '18, 2:41 p.m.
Hi there,

I wrote "In a work item attribute validator customization, how can I specify a value is invalid if they have not linked a Parent?" I can do most of that - I am just not sure how to determine if the record has a Parent link on it or not. I don't care anything about the Parent, just that it exists. Any ideas?

dojo.provide("validate.checkParent");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
 (function() {
    var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
    dojo.declare("validate.checkParent", null, {
    validate: function(attribute, workItem, configuration) {
            var pActivity= workItem.getValue('itops.activity.type.addable');       
            if (pActivity = "Project") {
                // NEED TO CHECK FOR PARENT LINK
            } else {
                return Status.OK_STATUS;
            }
        }
    });
})();

All help is appreciated!

Accepted answer


permanent link
Davyd Norris (2.4k217) | answered Nov 10 '18, 5:23 p.m.
edited Nov 13 '18, 3:18 p.m.
You can use the WorkItemProxy to get the links and then look for one of endpoint type parent

Something like this:
validate: function(attribute, workItem, configuration) {
  var pActivity= workItem.getValue('itops.activity.type.addable');       
    if (pActivity = "Project") {
      var proxy = workItem.getProxy();
      var linkArray = proxy.getValue({path:["linkTypes"]});
        if (linkArray.find(function(link) { return link.endpointId === "parent" })) {
          return Status.OK_STATUS;
        }
     } else {
       return Status.OK_STATUS;
     }
  }
});
Donna Thomas selected this answer as the correct answer

Comments
Ralph Schoon commented Nov 11 '18, 9:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Does this also work in the Eclipse client?


Davyd Norris commented Nov 11 '18, 5:25 p.m.
It appears the RTC Eclipse Client is a bit behind in its JavaScript support - I had to go in and add a bunch of semi colons in my own code in order to get it to even run.

After doing that though, I found that the embedded JavaScript engine is quite a bit behind the browser and is missing several elements including the extended dojo XMLHttpRequest provided by jazz.client, and the WorkItemProxy.

This means the getProxy() function is not implemented and there's no com.ibm.team.workitem.web.cache.internal.WorkItemProxyFactory either.

So no, at this point, the Eclipse Script engine won't run anything but the most basic code.

In my case it's not a problem because my clients are only using the browser. In addition, they are all in SaaS environments so I have no access to the server to add any Java based extensions. I think this is going to become more problematic as more people adopt the IBM SaaS service (which is very good I might add) so we should push for parity in the Eclipse client.



Donna Thomas commented Nov 13 '18, 2:46 p.m.
Davyd - you are awesome! Fortunately these users will all be using the web client.

I learned a lot from your reply. I know this is asking a lot more... Is WorkItemProxy described anywhere on Jazz.net or a in a blog anywhere? I'm thinking that's what I could use to get details about the Parent record.

Thanks!

3 other answers



permanent link
Ralph Schoon (63.3k33646) | answered Nov 10 '18, 6:43 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Nov 10 '18, 6:43 a.m.
The JavaScript attribute customization API does not provide access to the links of a work item - see supported types in the API.

You would have to use a Java Extension to do this.


permanent link
Davyd Norris (2.4k217) | answered Nov 13 '18, 3:17 p.m.
Hi Donna,

There are some vague details in the wiki if you search - try starting at:

or the article on contributing an attribute presentation element:

and there are also about half a dozen replies in this forum by Jonas Studer - his responses were the ones that alerted me to the fact the proxy even existed, and he's got some code snippets that may help. You should be able to get the parent itemId from the array returned above, and then you can try something like:
dojo.require("com.ibm.team.workitem.web.cache.internal.WorkItemProxyFactory");

var WorkItemProxyFactory = com.ibm.team.workitem.web.cache.internal.WorkItemProxyFactory;
var params = { id: <parentItemId>,
                       createIfNeeded: true,
                       doNotCache: true,
                       doNotGetFromCache:true};
var proxy = WorkItemProxyFactory.getWorkItemProxy(params);

// you may also need this line to fetch the data, but not sure
proxy.initialize(params);

I think it's obvious that, given this whole subject is not formally documented anywhere, and that it doesn't work in the Eclipse UI, it's an internal capability that might break or disappear at any stage, so best you can hope for is that it helps for now.

One person has even told me it was deprecated a while ago for the MVVM pattern, but then when I looked in the wiki for MVVM I found the Proxy objects still being used, so I'm trying to get more info. The way I found out all this detail was to add a
console.log(proxy);
to my code, and then open the Developer Tools in my browser and clicked through the attributes and methods on the class, which took me to the JavaScript. I then looked at how the methods were used and combined this with the info in the wiki.

I really hope this element (or whatever has supposedly replaced it) gets properly documented - I can see that there will be a huge need for this sort of client side scripting as the IBM CLM SaaS offering takes off. In the last 2 years I have only had one client choose on prem installation, the rest of them have found the SaaS offering a very attractive option - the client I am using the proxy with has about 300 users registered in their SaaS instance.



permanent link
Ralph Schoon (63.3k33646) | answered Nov 14 '18, 6:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Nov 14 '18, 6:05 a.m.

 David,


you should create an enhancement request. 

I had asked for enhancements for attribute customization in the past and there was quite a reluctance to provide anything. One reason was that excessive attribute customization can bring down the servers. We had several customer cases. A case with a customer where a theme rendered the system pretty unresponsive. Another one here in the forum some weeks ago where a huge amount of calculated values took more than 20 seconds to load a work item to the state where you could edit. 

Value sets with tens of thousands of entries are another indicator for the fact something is going over board.

Given this and my experience over the years with questions around customization in this forum and elsewhere hints that this can be a curse rather than a blessing, especially because you can go to town on customization without having to talk to someone who has experience with performance considerations.  

From what I can see there is no documentation for the proxy feature. The main source for what is available in attribute customization can be found here: https://jazz.net/wiki/bin/view/Main/AttributeCustomization.

Again, having said all that, if you desire an enhancement, create a request in the RTC project area or in the IBM Enhancement Request Community.


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.