It's all about the answers!

Ask a question

script based calculated values using custom attributes


Christine Makasy (731123) | asked Sep 09 '14, 2:55 a.m.
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

Accepted answer


permanent link
Dinesh Kumar B (4.1k413) | answered Sep 09 '14, 3:19 a.m.
JAZZ DEVELOPER
edited Sep 09 '14, 3:26 a.m.
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.
Christine Makasy selected this answer as the correct answer

Comments
Christine Makasy commented Sep 09 '14, 4:30 a.m.

Many thanks. Now I removed the second ), tried it again, but with the same result. The value entered in the attribute note1 will not be shown in the attribute based on the script.
I just want to display an attribute entry entered in an editor field in another editor field.

Could you please have a look again, thanks, Christine            


Dinesh Kumar B commented Sep 09 '14, 5:16 a.m.
JAZZ DEVELOPER

ok two more things to check are :
1.  setting of the calculated value script to the attribute which is expected to receive the return value from the script
2.  attribute dependency on the source attributes.

For the ID, It's the id of the attribute itself and not a combination of multiple fields. 

Assuming you are using the Eclipse Client, if you double click on the attribute from the attributes list for the work item type, the value that shows up in the ID field is what you should be using.


and please go through the Lab Ralph suggests.  Its extensive, clear and a nice asset on customizations in RTC.


Susan Hanson commented Sep 09 '14, 5:48 a.m.

Have you done some console.log() statements to validate that you are getting what you think?  For example, what is the value of n before the ParseInt that gets returned?


Christine Makasy commented Sep 23 '14, 8:57 a.m.

Many thanks for your help, the hint with the console.log() Statement leaded to the solution.

One other answer



permanent link
Ralph Schoon (63.5k33646) | answered Sep 09 '14, 3:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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");


Comments
Christine Makasy commented Sep 09 '14, 4:38 a.m.

Sorry, but I don't understand the expression my.custom.attribute.id. I addressed the my custom attribute with the category and the id mentioned in the process configuration source. Could you please explain?
Christine


Ralph Schoon commented Sep 09 '14, 5:07 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You basically click on the custom attribute, go to the identifier text box, copy the content and paste it into the quotation marks. E.g you replace the my.custom.attribute.id with the ID string for your attribute. The work item type category does not play any role in the ID for the attribute. I'd suggest to follow the links I provide above. It is worth it.


Christine Makasy commented Sep 23 '14, 8:56 a.m.

many thanks for your help, it is solved now

Your answer


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