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

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

0 votes


Accepted answer

Permanent link
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

0 votes

Comments

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            

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.

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?

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


One other answer

Permanent link
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");

0 votes

Comments

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

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.

many thanks for your help, it is solved now


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
× 6,120
× 42
× 35
× 4
× 2

Question asked: Sep 09 '14, 2:55 a.m.

Question was seen: 5,079 times

Last updated: Sep 23 '14, 8:57 a.m.

Confirmation Cancel Confirm