script based calculated values using custom attributes
Just for testing purposed I tried to add a script based values to the defect editor and I don't know how to address these script based values.
Please find below the script:
dojo.provide("com.example.calculateValue");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.example.calculateValue", null, {
getValue: function(attribute, workItem, configuration) {
//var n = parseInt(workItem.getValue('note1ID'));
var n = workItem.getValue("com.ibm.team.workitem.workItemType.note1ID"));
var p = parseInt(workItem.getValue('pointsID'));
//var n = 99;
//var p = 3;
var calcNotePoints;
calcNotePoints = n * p;
//calcNotePoints = 444;
return parseInt(n);
Having just a simple assignment of a value like calcNotePoints = 444; the attribute in the work item editor shows the value.
Do you have an idea how to address these custom values in the Java Script?
Many thanks, Christine
Please find below the script:
dojo.provide("com.example.calculateValue");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.example.calculateValue", null, {
getValue: function(attribute, workItem, configuration) {
//var n = parseInt(workItem.getValue('note1ID'));
var n = workItem.getValue("com.ibm.team.workitem.workItemType.note1ID"));
var p = parseInt(workItem.getValue('pointsID'));
//var n = 99;
//var p = 3;
var calcNotePoints;
calcNotePoints = n * p;
//calcNotePoints = 444;
return parseInt(n);
Having just a simple assignment of a value like calcNotePoints = 444; the attribute in the work item editor shows the value.
Do you have an idea how to address these custom values in the Java Script?
Many thanks, Christine
Accepted answer
Hi Christine,
There is additional closing parenthesis in the following code piece :
var n = workItem.getValue("com.ibm.team.workitem.workItemType.note1ID"));
please correct it and check if it helps.
In general to be able to access the custom attributes, you have to
a. refer to their ID
b. placed within single or double quotes
c. from workItem.getValue.
I do see that you are mostly covering all the three mentioned above, but that extra ) may be causing the failure.
one more to check is the return value, i see that you are returning n and not calcNotePoints, not sure if you intended to.
hope it helps.
There is additional closing parenthesis in the following code piece :
var n = workItem.getValue("com.ibm.team.workitem.workItemType.note1ID"));
please correct it and check if it helps.
In general to be able to access the custom attributes, you have to
a. refer to their ID
b. placed within single or double quotes
c. from workItem.getValue.
I do see that you are mostly covering all the three mentioned above, but that extra ) may be causing the failure.
one more to check is the return value, i see that you are returning n and not calcNotePoints, not sure if you intended to.
hope it helps.
Comments
One other answer
I don't understand the question. However, if you are looking for more information have a look at
https://jazz.net/wiki/bin/view/Main/AttributeCustomization
https://jazz.net/library/article/1093 Lab 5
If you ask for the custom attributes and how to access them in a script, use
workItem.getValue("my.custom.attribute.id");
https://jazz.net/wiki/bin/view/Main/AttributeCustomization
https://jazz.net/library/article/1093 Lab 5
If you ask for the custom attributes and how to access them in a script, use
workItem.getValue("my.custom.attribute.id");