Attribute Customization: Can a Calculated Value use the contents of Checkbox Enumeration List without a save using JS?
In all cases, the necessary dependencies in the Types and Attributes GUI are configured.
This pertains to JavaScript Calculated Values entered into the Attribute Customization GUI.
Is there anyway for a Checkbox Enumeration List Presentation information to be available via a workItem.getValue() function in our scripts?
4 answers
- Created an enumeration called androidVersions, added several, for example, name="KitKat" id="Android 4.4". See discussion here regarding renaming ids. if that interests you.
- Created a custom field for androidVersions as an enumerated checkbox presentation.
- Created a custom string field for androidVersionNumber and made it readonly and dependent on androidVersions attribute.
- Created a script that used workItem.getValue("androidversion"); to retrieve current checked values.
- Concatenated values of the ids from the array returned in previous step. Since there may be multiple values, you get an array of objects returned and you'll need to piece it apart to assign the value.
- Returned string of concatenated values.
dojo.provide("edu.millard.forumtest.ValueProvider");
(function() {
dojo.declare("edu.millard.forumtest.ValueProvider", null, {
getValue: function(attribute, workItem, configuration) {
var selectedValues = workItem.getValue("androidversion");
var valueNames = '';
for (var i=0; i < selectedValues.length; i++) {
valueNames += selectedValues[i].id + " "
}
if (!selectedValues) return "idk";
else return valueNames;
}
});
})();
Comments
Hello Millard,
I tried implementing this feature . I have a enumeration list with 20 values. Now when I select 12 values and save the workitem. It looks good. However when I select 13 values. I get this error.
I think it's because Medium String can hold only (1000 bytes of text). Now to solve this we need to make it as Large String (32768 bytes of text). But I'm not sure how to do that.
Please clarify the same..
Regards
Vishnu M
you cannot change an attribute type. you can create another one.
Hello Sam,
The attribute type is enumeration. What other type should I create it with ?
Regards
Vishnu M
I think the attribute to RTC is a String, and you PUT an enum type presentation over it.
your prior post said:
>I have a enumeration list with 20 values. Now when I select 12 values and save the workitem. It looks good. However when I select 13 values. I get this error.
12 items in 1000 chars is average 83 chars each.. pretty big for an enum choice.
Hello Sam,
I have created an enumeration called "System" which has 20 values(system1,system2...system20) and then created an attribute "System" of type Enumeration list with presentation Checkbox enumeration list.
Now when I choose 12 values from the checkboxes, It saves fine.
When I select 13 or more values then I get the error : value of attribute "mediumStringExtenstions.value" is 1438 bytes, which is greater than the allowed
encoded length of 1000 bytes."
May be define it in the script?
Here's the script definition , I have mentioned dojo.require("dojo.string")
I'm guessing RTC assumes it's medium. How do I change it to large ?
-----------------------
dojo.provide("com.example.test.system");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.string");
(function() {
------------------------------------------------
ah, sorry.. you are using the builtin enumeration list attribute type..
I don't think there is a way to change its storage size.
I have implemented the same feature in my project area and it is working fine as excepted.
I would suggest you to use a attribute type of Large String will resolve your problem.
Find the script below:
dojo.provide("scripts.defect.targetdatabases");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.string");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("scripts.defect.targetdatabases", null, {
getValue: function(attribute, workItem, configuration) {
var selectedValues = workItem.getValue("TargetDatabases");
var valueNames = '';
for (var i=0; i < selectedValues.length; i++) {
valueNames += selectedValues[i].label + ","
}
if (!selectedValues){
return "";
}
else{
return valueNames.substring(0,valueNames.length-2);
}
}
});
})();
Hi All,
I tried to return a value to “Enumeration List” of “Picker Enumartaion List”, I’m getting below error?
Its working for “Enumeration” of drop down value
Error running operation 'Saving Work Item'
java.lang.ClassCastException: com.ibm.team.workitem.common.model.Identifier incompatible with java.util.Collection
Script :
dojo.provide("edu.millard.forumtest.ValueProvider");
(function() {
dojo.declare("edu.millard.forumtest.ValueProvider", null, {
getValue: function(attribute, workItem, configuration) {
var selectedValues = workItem.getValue("branch3");
var valueNames ="enumBranch.literal.l4";
return valueNames;
}
});
})();
Comments
sam detweiler
Oct 28 '13, 6:55 p.m.as far as I know, only default value initializer scripts are run on workitem load..
everything else is run on workitem save.
I'm not aware of ANY scripts that are run realtime while typing or navigating between fields.
Alexander Dawson
Jul 15 '13, 11:42 a.m.Other types of presentations do update live on fields that have them listed as dependencies. The Checkbox Enumeration List appears to be behaving differently.
Tayane Fernandes
Oct 28 '13, 2:09 p.m.Hi Alexander Dawson!
Millard Ellingsworth
FORUM ADMINISTRATOR / JAZZ DEVELOPER Oct 28 '13, 2:13 p.m.@abdawson1 is correct. According to this article, calculated value scripts are invoked whenever a dependent item changes.
sam detweiler
Oct 28 '13, 2:40 p.m.good old dependencies.. always a rule changer!