It's all about the answers!

Ask a question

Rational Team Concert - Use HttpConnectorParameters on Calculated Value script based custom attribute


Juan Martín Alberti (201417) | asked Mar 14 '14, 10:54 a.m.
Hi everybody!
I want to ask if there's a way to use HttpConnectorParameters on a Calculated Value (script  based) for custom attributes.

This is an extample of how to use HttpConnectorParameters on a Set Value (script based):

dojo.provide("net.jazz.example.scripted.oslc.wiids.ValueSetProvider"); 

dojo.require("com.ibm.team.workitem.api.common.connectors.HttpConnectorParameters"); 

(function() { 
    dojo.declare("net.jazz.example.scripted.oslc.wiids.ValueSetProvider", null, { 

        getValueSet: function(attributeId, workItem, context){ 

        var params= new com.ibm.team.workitem.api.common.connectors.HttpConnectorParameters(); 
        params.url="<server>/ccm/oslc/contexts/<pareauuid>/workitems"; 
        params.xpath= "//Collection/ChangeRequest"; 
        params.columnXpaths= ["./identifier"]; 
        params.columnIds= ["wid"]; 
        params.ignoreInvalidCertificates=true; 
        params.useOAuth=true; 

        var connector= context.getDataConnector("HttpConnector"); 
        var values= connector.get(params); 
        var result= []; 

        while(values.hasNext()){ 
            var entry= values.next(); 
            var wiIDs= entry.getById("wid"); 
            result.push(wiIDs); 
        } 

        return result; 
    } 
   }); 
})();

We want to do something similar but to the Calculated Value custom attribute.

We want to return to a field something that is calculated from the HttpConnectorParameters. Something like this:

dojo.provide("com.example.ValueProvider");
dojo.require("com.ibm.team.workitem.api.common.connectors.HttpConnectorParameters"); 

(function() {
    dojo.declare("com.example.ValueProvider", null, {

        getValue: function(attribute, workItem, context) {
        var params= new com.ibm.team.workitem.api.common.connectors.HttpConnectorParameters(); 
        params.url="<server>/ccm/oslc/contexts/<pareauuid>/workitems"; 
        params.xpath= "//Collection/ChangeRequest"; 
        params.columnXpaths= ["./identifier"]; 
        params.columnIds= ["wid"]; 
        params.ignoreInvalidCertificates=true; 
        params.useOAuth=true; 

        var connector= context.getDataConnector("HttpConnector"); 
        var values= connector.get(params); 
        var result= ''; 

        while(values.hasNext()){ 
            var entry= values.next(); 
            var wiIDs= entry.getById("wid");
    result = result + ', ' + wiIDs; 
        } 

        return result; 
        }
    });
})();

Comments
Millard Ellingsworth commented Mar 14 '14, 12:51 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

Are you saying that  you use the first one successfully yet the second one doesn't work? I can't quite tell what your question is. If you have tried the second example and it doesn't work, what happens? And what versions of RTC are involved? Also, because of how these are called, I'd be carefully doing any possible long-running operation in a scripted customization. Calculated Value scripts are run on both the client and the server, so whatever you do must work from either side and produce the same result no matter how many times it is run..


Juan Martín Alberti commented Mar 14 '14, 1:46 p.m. | edited Mar 14 '14, 2:06 p.m.

Millard,


Are you saying that  you use the first one successfully yet the second one doesn't work?
Yes, the first one works and the seconde one doesn't. The second one doesn't return any value.

I can't quite tell what your question is
My question is how we can return values in a Calculated Value (script based) including HttpConnectorParameters object. We analized this script and the error is when we want to access to the "context" object. Apparently the context object doesn't come as a parameter in a getValue function.

If you have tried the second example and it doesn't work, what happens?
Answered.

And what versions of RTC are involved?
Rational Team Concert 4.0.3.

Any idea to access HttpConnectorParameters from a Calculated Value (script based)?




2 answers



permanent link
Millard Ellingsworth (2.5k12431) | answered Mar 14 '14, 2:45 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER
edited Mar 14 '14, 2:47 p.m.
Ah, wishful thinking: the third argument to getValue() is configuration, not context as for the value provider. See https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Calculated_values and https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript

Inside a Value Set provider you can get a new instance of any contributed data connector by calling:

  • For Javascript:  context.getDataConnector("connectorId")
is a feature of being in the context of a Value Set provider -- this simply isn't a feature of a Calculated Value customization. If you had debugging turned on or were watching your JavaScript console, I assume you would have seen errors. Some details here: https://jazz.net/library/article/1360

Comments
Juan Martín Alberti commented Mar 14 '14, 8:44 p.m.

Tanks Millard, but that does't answer the question. That only says why this is not working. Is there any waty to access a Http Data Connector on a Calculated Vaue provider?


permanent link
Noel Gimeno (1521017) | answered Mar 10 '16, 11:00 a.m.
edited Mar 10 '16, 11:04 a.m.
Hello Juan,

As an alternative, as you cannot access the "HttpConnectorParameters " within a calculated value, you can use a http client in the javascript of your calculated value to connect to a requested service (OSLC, REST, etc.) and then retrieve the info you need.

Based on Millard Ellingsworth comment, the http reuest cannot be asynchronous within a Calculated value:
https://jazz.net/forum/questions/128516/work-item-calculated-values-using-soa-call

But you can still create a synchronous http request to RTC and gather the info you need:

var url_resource = "http://myServer"
          var request = {
url: url_resource,
                    sync : "true",
                    handleAs: "json",
                    headers: {
                              accept: "application/json"
                    }};
var d = jazz.client.xhrGet(request);

This will return a JSON object.

Take into account that this is a synchronous call, with the consequences that it implies:
http://stackoverflow.com/questions/748175/asynchronous-vs-synchronous-execution-what-does-it-really-mean

I have one question open about the possibility of asynchronous calls in case you want to follow it:
https://jazz.net/forum/questions/218076/asynchronous-http-calls-in-a-script-based-calculated-value

Your answer


Register or to post your answer.