It's all about the answers!

Ask a question

How to get value of attribute in Java based calculated value provider plug-in


Mallanagouda Patil (40815) | asked Jun 27 '17, 8:18 a.m.
edited Jul 04 '17, 4:21 a.m. by Ralph Schoon (63.5k33646)

 Hi All,

Developing Java based Calculated Value Provider plug-in to integrate RTC with external application through REST APIs. Need to get value of the attribute and send it to external application through REST API. The problem is that the getValue(IAttribute) API of WorkItem returns empty when workitem created in WebUI however the same work when workitem created in EclipseUI. It works when Workitem Save button is pressed in WebUI. However it does not when dependency triggered. 

Not sure why this change in behaviour while working WebUI & EclipseUI. It appears that script is needed to make it work with WebUI but how to integrate Script and Java method?. 

If not is there way to consume REST APIs in calculated value provider script?. I do not see any such support as HTTPConnect facility limited to Validator only. 

Please suggest. Thanks in advance!.


Comments
Mallanagouda Patil commented Jun 28 '17, 12:27 a.m.

 Here is the sample code am trying

public class GetSummary implements com.ibm.team.workitem.common.internal.attributeValueProviders.IValueProvider<Object> {

@Override
public Object getValue(IAttribute attribute, IWorkItem workItem,
IWorkItemCommon workItemCommon, IConfiguration configuration,
IProgressMonitor monitor) throws TeamRepositoryException {
// TODO Auto-generated method stub
return workItem.getHTMLSummary().getPlainText();
}

}

Accepted answer


permanent link
Sharoon Shetty Kuriyala (55133) | answered Jun 28 '17, 8:23 a.m.
JAZZ DEVELOPER

 This works as designed, when using a Java based Calculated Value Provider, the provider gets triggered only on Save and not when it is dirty, however when using a script based value provider, it gets invoked when the work item is dirty because the script is loaded in the browser.

Mallanagouda Patil selected this answer as the correct answer

Comments
Mallanagouda Patil commented Jul 06 '17, 7:11 a.m.

Hi Shroon,
Same issue with script based value provider as well.
var summaryValue=workItem.getValue(WorkItemAttributes.SUMMARY);
      console.log("Get Summary Value : " +summaryValue);
The above API returns empty though text has been entered in Summary attribute. The same issue with String type attribute as well.
But works with enumeration or integer attributes

var severity= workItem.getValue(WorkItemAttributes.SEVERITY);
console.log("Severity value is " +severity);

https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Calculated_values
As per above article, it suppose to work for String, Integer and other attributes as well.
Is there any change in 6.0.1?. I had developed calculated value provider scripts in 5.0.1 for computation purpose and it had worked.


Mallanagouda Patil commented Jul 06 '17, 7:12 a.m.

/sample script/
dojo.provide("com.example.getsummaryvalue");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
    var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
    dojo.declare("com.example.getsummaryvalue", null, {
        getValue: function(attribute, workItem, configuration) {
            var isSet=workItem.isAttributeSet(WorkItemAttributes.SUMMARY);
             console.log("Get Summary Value Script : isSet : " +isSet);
             var summaryValue=workItem.getValue(WorkItemAttributes.SUMMARY);
             console.log("Get Summary Value : " +summaryValue);
            return summaryValue;
        }
    });
})();

2 other answers



permanent link
Sharoon Shetty Kuriyala (55133) | answered Jun 28 '17, 10:13 a.m.
JAZZ DEVELOPER

 I just noticed that you are also looking at an alternative to invoke REST service from a script, this should be possible. Have you tried invoking a REST service from a script and have hit any issues with that approach? I would expect it to work like any REST call done via a javascript for example.


Comments
Mallanagouda Patil commented Jul 04 '17, 2:57 a.m.

Sharoon
I could progress by developing DataConnector plug-in similar to HTTPConnector and it helped me to consume external REST service in a script. It is explained here https://jazz.net/wiki/bin/view/Main/DataSourceValueSetProviders#Tutorial_for_providing_a_custom. Thanks.


permanent link
Mallanagouda Patil (40815) | answered Jul 04 '17, 2:58 a.m.

Develop data-connector plug-in as explained here https://jazz.net/wiki/bin/view/Main/DataSourceValueSetProviders#Tutorial_for_providing_a_custom and then use the same in Calculated Value Provider Script to integrate with external REST services.

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.