It's all about the answers!

Ask a question

Calulated Values using Script Based for a Custom Attribute


Girish Chandra P (853246) | asked Jul 15 '13, 8:49 a.m.
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.

Accepted answer


permanent link
Dinesh Kumar B (4.1k413) | answered Jul 15 '13, 10:37 a.m.
JAZZ DEVELOPER
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
Girish Chandra P selected this answer as the correct answer

5 other answers



permanent link
Girish Chandra P (853246) | answered Jul 24 '13, 5:31 a.m.
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 support.
Girish

permanent link
Dinesh Kumar B (4.1k413) | answered Jul 15 '13, 9:59 a.m.
JAZZ DEVELOPER
have you enabled the script attachments!

if not, you can reach it using :
https://localhost:9443/ccm/admin > Server tab > Configuration > Advanced Properties > Work Item Component > Enable Process Attachment Scripts
and set the property to true

Comments
Girish Chandra P commented Jul 15 '13, 10:24 a.m.

Yes Dinesh I have enabled the script attachments !!
Is there any way I can run my scripts and check the error  ?


permanent link
sam detweiler (12.5k6195201) | answered Jul 15 '13, 9:11 a.m.
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>

Comments
Girish Chandra P commented Jul 15 '13, 9:17 a.m.

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);           
        }
    });
})();


sam detweiler commented Jul 15 '13, 9:26 a.m.

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


permanent link
Dinesh Kumar B (4.1k413) | answered Jul 15 '13, 9:02 a.m.
JAZZ DEVELOPER
also check if the custom attribute has its dependency set on the Time Spent and Estimate attributes...

Comments
Girish Chandra P commented Jul 15 '13, 9:10 a.m.

Yes i have set the dependency

But I did not understand
you never setup the variable WorkItemAttributes
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var workitemtype = workItem.getValue(WorkItemAttributes.TYPE);


some one help me on this !


permanent link
sam detweiler (12.5k6195201) | answered Jul 15 '13, 8:59 a.m.
you never setup the variable WorkItemAttributes
<code>
           var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
           var workitemtype = workItem.getValue(WorkItemAttributes.TYPE);
</code>

Comments
Girish Chandra P commented Jul 15 '13, 9:03 a.m.

Thanks for reply .. Can you elaborate it more ..


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.