It's all about the answers!

Ask a question

how to fetch/pull/extract data from dashboard widgets of RTC.


Krunal Gaoli (67667) | asked Mar 16 '17, 6:38 a.m.

I have a widget that contain a list of defect work items and there is a count present on widgets i.e how many defect work items are in the given widgets .I want to know how to pull that  count value from widgets and have some calculus on it.

Anyone can help me on same?

Best Regard
Krunal.


Comments
Krunal Gaoli commented Mar 21 '17, 9:19 a.m. | edited Mar 24 '17, 12:51 a.m.

 Thanks Jonas, 


Can you please give it to me in JAVA Script.

I want to show it in the form of Widgets.

Best Regards,
Krunal.

One answer



permanent link
Jonas Studer (207917) | answered Mar 20 '17, 4:37 a.m.

Hello there Krunal,

First thing.
In what language? Javascript or Java?

Second thing.
Is this a built in Widget or a third party one?

Greetings


Comments
1
Jonas Studer commented Mar 21 '17, 9:48 a.m.

Depends how you can access the Widget.

1:
If its a built in Widget you have to access it externally.
Maybe its easier to just read the HTML-Label if you need that value.
But I do NOT suggest this!

2:
If it's your own code you just have to read the distinct value.
Then it depends on how this value is  set. Maybe Array.length.

I really don't get what you want to achieve since it's not that easy to access data inside a Widget. The other point is, that this value is only present when this particular widget is loaded. So it's kind of dangerous to build logic on that value.


Krunal Gaoli commented Mar 22 '17, 1:56 a.m.

 Hi Jonas,


I would like to describe you my use case for same.

Case:1
I want to calculate Defect Density for my Project. we are going to calculate Defect Density using below formula:
 i. DD=Number of Defects/ Kilo Lines of Code.
 ii.DD=Number of Defects/No of test cases. 
 
Case:2
I want to show the calculated value in below format
i. If possible in the form of Report. 
ii. In the form of Widgets on dashboard.

Challenges are:
1. How to fetch live number of  defects count data
2. How to show the calculated DD on Dashboard.

Best Regards.
Krunal


Jonas Studer commented Mar 22 '17, 3:07 a.m.

Hy Krunal,

Ok I might have an Idea how you could achieve that use case.
But remember, I'm just useful for Javascript questions since I haven't that much experience on the client side Java API.

My steps to achieve that would be:
1: Build a query which represents the data I need.
2: Get the query data over XHR
  -Now you know exactly how much defects are in your system.
   Where do you store the information about the "Kilo Lines of Code"?
   If it's a value inside the defect it's also easy to calculate this because through the query you'll also have the different Workitems (defects in that case)

3: Display the whole thing in HTML the way you want.
1: How to detect how many Defects are in the System?

I'd suggest you to build this logic with a query.

2: Then load the query into your Widget with XHR.


1
Jonas Studer commented Mar 22 '17, 3:18 a.m.

Maybe you do wonder how could I access a query and its data?
This will do the trick
https://myServer.xy/application(This case ccm)/oslc/queries/queryID
https://myServer.xy/ccm/oslc/queries/_te5rttgzuhjit45


Jonas Studer commented Mar 22 '17, 3:19 a.m.

Logic
require -> "dojo/request/xhr"
require -> "dojo/Deferred"
getRequest: function(url, returnType, preventCache){
    returnType = (returnType) ? returnType : "text";
    preventCache = (preventCache) ? preventCache : false;
    //Header should be based on the return type
    var xhrHeader = {"accept":"application/xml"};
    var deferred = new Deferred();
    xhr(url, {
        handleAs: returnType,
        method: "GET",
        headers: xhrHeader,
        preventCache: preventCache,
        sync: false
    }).then(function(response){
        deferred.resolve(response);
    }, function(error){
        deferred.reject(error);
    });
    return deferred;
},


Jonas Studer commented Mar 22 '17, 3:19 a.m.

/*Usage*/
var  queryToLoad = "https://myServer.xy/ccm/oslc/queries/_te5rttgzuhjit45"
getRequest(queryToLoad, "json", true).then(function(innerResponse){
    //Handle success
}, function(err){
    //Handle error
});


Krunal Gaoli commented Mar 22 '17, 4:00 p.m.

 Thanks Jonas,


1.
I am planning to store the value of Kilo Lines of Codes in Customized Work Item.

2.
Regarding number of defects in a system, we can achieve this using query(Defect list ) and Dashboard widgets  (on upper right side its shows number of defects) I want to pull that count (number of defects)
into my WI attribute and have some calculus on it.
I think REST(XHR - Get) will be helpful for me.

If you have any suggestion on it, will be admirable.

Thanks a lot.
Krunal 
krunalgaoli@gmail.com

showing 5 of 7 show 2 more comments

Your answer


Register or to post your answer.