Calulated Values using Script Based for a Custom Attribute
I have two attributes in FPM :TIME_SPENT & ESTIMATE ,
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.
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
like sam suggested earlier, you could run these scripts with console.log at various places to see where the execution is failing... the log is printed to the .log file under .metadata in the eclipse workspace, you will find the log entries in these files:
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
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
also check if the custom attribute has its dependency set on the Time Spent and Estimate attributes...
your code does
<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>
<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
have you enabled the script attachments!
if not, you can reach it using :
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
Hello Dinesh / Sam Detweiler ,
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 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