Calulated Values using Script Based for a Custom Attribute
I have created an custome attribute by name Completedp with id pc
my Script is as follows
dojo.provide("com.example.ValueProvider");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
dojo.declare("com.example.ValueProvider", null, {
getValue: function(attribute, workItem, configuration) {
var r1=workItem.getValue(WorkItemAttributes.TIME_SPENT)
var r2=workItem.getValue(WorkItemAttributes.ESTIMATE)
return (r1/r2*100);
}
});
})();
I am not able to see the results in custom attribute .Please some one help me in this script.
Accepted answer
Server: JazzTeamServer/server/tomcat/work/Catalina/localhost/ccm/eclipse/workspace/.metadata/.log
Eclipse client: client/eclipse/workspace/.metadata/.log
on the Web UI, you could use any generic script debugger, Firebug is my favorite.
here is a lot of information on how you could debug the Web UI
https://jazz.net/wiki/bin/view/Main/WorkItemsWebDebugging
to me, the code appears fine after applying the correction suggested by Sam.
another approach that you might want to try is to start with a default script and then start adding your functionality one line at a time to reach to the problematic piece of code
hope this helps
5 other answers
<code>
var r1=workItem.getValue(WorkItemAttributes.TIME_SPENT)
var r2=workItem.getValue(WorkItemAttributes.ESTIMATE)
</code>
where did you create the variable WorkItemAttributes?
you told dojo that you needed the class.
<code>
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
</code>
but you never did the variable creation.
here is one of my javascript functions (a conditional)
<code>
dojo.provide("com.xx.defect.resolution.Condition");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
dojo.declare("com.xx.defect.resolution.Condition", null, {
matches: function(workItem, configuration)
{
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var rc = false;
var workitemtype = workItem.getValue(WorkItemAttributes.TYPE);
console.log(workitemtype);
if( workitemtype ==="defect" )
{
var state= workItem.getValue(WorkItemAttributes.STATE);
console.log(state);
if(state === "3" )
{
var resolution = workItem.getValue(WorkItemAttributes.RESOLUTION);
console.log(resolution);
if(resolution === "3" )
{
rc = true;
}
}
}
return rc;
}
});
})();
</code>
Comments
I have changed my code as follows , but still not working !!
dojo.provide("com.example.ValueProvider");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
var workitemtype = workItem.getValue(WorkItemAttributes.TYPE);
dojo.declare("com.example.ValueProvider", null, {
getValue: function(attribute, workItem, configuration) {
var r1=workItem.getValue(WorkItemAttributes.TIME_SPENT)
var r2=workItem.getValue(WorkItemAttributes.ESTIMATE)
return (r1/r2*100);
}
});
})();
note that my setup is AFTER the function statement
try this
<code>
getValue: function(attribute, workItem, configuration) {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
var workitemtype = workItem.getValue(WorkItemAttributes.TYPE);
</code>
you might also consider adding the console.log() stmts to aid in the debugging
if not, you can reach it using :
https://localhost:9443/ccm/admin > Server tab > Configuration > Advanced Properties > Work Item Component > Enable Process Attachment Scriptsand set the property to true
Thanks for your kind help and support.
I did a mistake when binding the type to the custom attribute , ( I made it has type contributor instead of long).
After instering the debug/Log I could check the answer in logs and corected the same .
Thanks for your kind support. Girish