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

Error when trying to implement a Default Value script

 Hi 

We are using RTC 5.0

I am trying to implement a Default Value into the Estimate Attribute based on a selected value in a Custom Attribute field ,ie,
If the value selected in the custom attribute field = Medium Enhancement, then the Estimate Field should default to a value of 60 Hours.

I used the following script;

dojo.provide("com.example.estimatedTime");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {

var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;

var estimatedTime= dojo.declare("com.example.estimatedTime", null, {
getDefaultValue: function(attribute, workitem, configuration) {
var estimatedTime = parseFloat(workitem.getLabel(String "service_Classification"));
if estimatedTime === "service_Classification.literal.l6"); {
return "30";
}
else if estimatedTime === "service_Classification.literal.l13"); {
return "60";
}
else if estimatedTime === "service_Classification.literal.l8"); {
return "90" ;
}
}
});
})();

I am getting the following error;

2016-04-23 16:11:30,753 [ccm: AsynchronousTaskRunner-2 @@ 16:11] ERROR com.ibm.team.workitem.common                        - Error invoking value provider 'com.ibm.team.workitem.valueproviders.VALUE_PROVIDER._uLJToAlaEeauvdaUeukNjg'
com.ibm.team.rtc.common.scriptengine.UnknownTypeException: 'com.example.estimatedTime' is not a constructor

Any and all assistance will be greatly appreciated.

Kind Regards

Glenn
 

0 votes


Accepted answer

Permanent link
Your script is malformed, hence the function is invalid. It looks a bit funny, why do you have the "var estimatedTime= dojo.declare(..." bit? It should've just been "dojo.declare(...". Maybe you just copied something to the wrong place without realizing it?
Glenn Watkins selected this answer as the correct answer

0 votes

Comments

  Hi Donald


Please see below

Kind Regards
Glenn




 Hi Donald

Thanks for your reply and advice, I have removed the bit as you mentioned and the script now looks as follows;

 dojo.provide("com.example.estimatedTime");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {

var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;

dojo.declare("com.example.estimatedTime", null, {
getDefaultValue: function(attribute, workitem, configuration) {
var estimatedTime = parseFloat(workitem.getLabel(String "service_Classification"));
if estimatedTime === "service_Classification.literal.l6"); {
return "30";
}
else if estimatedTime === "service_Classification.literal.l13"); {
return "60";
}
else if estimatedTime === "service_Classification.literal.l8"); {
return "90" ;
}
}
});
})(); 

I am still not getting the field to populate and the logs are giving the same error message. I would appreciate any help and advice on this.

Kind Regards
Glenn

Glenn, you really have to work on your coding skills, I'm sorry to say. It takes much more time to figure out what's wrong with your code than write my own version.  Here is a list of the errors that I can spot, so far.
1. Suspicious use of ParseFloat() function (why?).
2. Incorrect use of workitem.getLabel() - it should be getValue() if you want to use Ids.
3. Incorrect use of "===" (it means the object type has to match as well).
4. Extra semicolon (;) at the end of each "if" condition - syntax error!
5. Fail to return a value for a function (missing "else").

You first need to learn how to debug your code in a browser. Then start with the code skeleton (use the "fill in example" feature), and add your own code bit by bit. Verify that the code works at each step that you add more code.

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

Question asked: Apr 23 '16, 10:32 a.m.

Question was seen: 1,848 times

Last updated: Apr 26 '16, 9:47 p.m.

Confirmation Cancel Confirm