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

Script based Default Value

 Hi


I'm trying to create a new "Script Based Default Value" customization. It is simple just to hard code the owner of a certain type of workitem. I have created  calculated value scripts before and they run ok.
But I'm having trouble with the default value, is the structure the same? 
This is my code :

dojo.provide("Default_Value.task");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");



(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;

dojo.declare("Default_Value.task", null, {

    getValue: function(attributeId, workItem, configuration) {
var wi_type = workItem.getValue(WorkItemAttributes.TYPE);
var wi_owner = workItem.getValue(WorkItemAttributes.OWNER);
console.log("Type - " + wi_type);
console.log("Owner - " + wi_owner);
if (wi_type == "task"){
wi_owner  = "_p_g14CR6EeWmoeAO1lg85w"; 
}
    return wi_owner;
    }
});
})(); 

Thanks

0 votes


Accepted answer

Permanent link

The function should be getDefaultValue, not getValue. You can use the "Fill in example" link to get the skeleton of the script to avoid such simple mistake.
https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Script_based_default_values

Cesar Sasaki selected this answer as the correct answer

0 votes

Comments

 Hi Donald


I'm still having trouble using this code :
getDefaultValue: function(attribute, workItem, configuration) {
        var wi_type       = workItem.getDefaultValue(WorkItemAttributes.TYPE);
var wi_owner = workItem.getDefaultValue(WorkItemAttributes.OWNER);

if (wi_type == "task"){
wi_owner  = "_p_g14CR6EeWmoeAO1lg85w"; 
}
    return wi_owner;

More details please?

One scenario where it definitely will not work is creation. The default value provider will be executed on the server side before the editor is rendered on the web UI. At that time, all attributes have no value, so your script will always return null. You can add console.log() to debug and confirm this.

 The code above is bogus I suggest to read the instructions again https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Script_based_default_values 


workItem.getDefaultValue(WorkItemAttributes.TYPE);
must be workItem.getValue(WorkItemAttributes.TYPE);

the function was wrong as Donald correctly stated. Also Default values have very limited value since there is almost no data available on creation of the work item as Don also stated.

 I changed my script and worked I needed to add this :

(function() {
dojo.declare("default_value.owner", null, {

    getDefaultValue: function(attribute, workItem, configuration) {
    var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; 
 
    var wi_type = workItem.getValue(WorkItemAttributes.TYPE);

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

Question asked: Jul 03 '17, 7:10 p.m.

Question was seen: 1,578 times

Last updated: Jul 04 '17, 11:30 a.m.

Confirmation Cancel Confirm