Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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.

0 votes


Accepted answer

Permanent link
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

0 votes


5 other answers

Permanent link
you never setup the variable WorkItemAttributes
<code>
           var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
           var workitemtype = workItem.getValue(WorkItemAttributes.TYPE);
</code>

2 votes

Comments

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


Permanent link
also check if the custom attribute has its dependency set on the Time Spent and Estimate attributes...

1 vote

Comments

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
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>

1 vote

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


Permanent link
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

0 votes

Comments

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


Permanent link
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

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,952

Question asked: Jul 15 '13, 8:49 a.m.

Question was seen: 4,820 times

Last updated: Jul 24 '13, 5:31 a.m.

Confirmation Cancel Confirm