It's all about the answers!

Ask a question

RTC 4.x attr. customization: Need help to get a calculated value based on the values set in two other attributes


Maria Victoria Martinez Torino (14924559) | asked May 28 '14, 3:09 p.m.
Hi,

Let's say I have a work item type = "CustomType" with the following attribute configuration:
Attribute A: integer  - defaulted to "0" and with validator = "number greater or equal than 0".
Attribute B: enumeration, with possible values: Pass, Fail, N/A, Not Assessed - defaulted to "Not Assessed"
Attribute C: small string, having dependency on Attribute A and Attribute B and based on a "Script Based Calculated Value" provider.
This is the logic I have followed to build the provider:
if Attribute A = "Fail" or Attribute B = "Pass", then Attribute C = Attribute A,  else if Attribute B = "N/A", then Attribute C = "0"
And here is the script code I used to build "my_Provider":

dojo.provide("com.example.my_Provider");

(function() {
    dojo.declare("com.example.my_Provider", null, {

        getValue: function(attribute, workItem, configuration) {
                
        var BAttribute= configuration.getChild("BAttribute").getIdentifier();
        var AAttribute= configuration.getChild("AAttribute").getIdentifier();
      
        if (BAttribute == "Fail" || BAttribute == "Pass") {
            return AAttribute;
        } else {
            if (BAttribute == "N/A") {
                return 0;
            }
        }
            
        }
    });
})();


After saving the configuration, if I performed the following steps:
Scenario 1:
1) Created a work item based on type = "CustomType"
2) Entered a valid number on Attribute A, e.g. "5"
3) Selected "Pass" on Attribute B
4) Saved work item
5) Expected Result: Value displayed on Attribute C is 5" (= value entered on Attribute A)
    Actual Result: Value displayed on Attribute C is blank

Scenario 2:
1) Created a work item based on type = "CustomType"
2) Entered a valid number on Attribute A, e.g. "8"
3) Selected "N/A" on Attribute B
4) Saved work item
5) Expected Result: Value displayed on Attribute C is "0"
    Actual Result: Value displayed on Attribute C is blank


Could you please tell me what am I missing?

FYI - I am using the RTC client on a jazz server v4.0.6

Thanks in advance!
Vicky

One answer



permanent link
Brian Fleming (1.6k11928) | answered May 28 '14, 5:00 p.m.
The method to retrieve the value of your custom attributes is incorrect.  Instead of
        var BAttribute= configuration.getChild("BAttribute").getIdentifier();
        var AAttribute= configuration.getChild("AAttribute").getIdentifier();
you should have
        var BAttribute= workItem.getValue("BAttribute");
        var AAttribute= workItem.getValue("AAttribute");

The argument to the getValue method is the attribute identifier.  For enumerations, this will return the identifier of the value, and not the value itself (i.e. it will not return "Pass" or "Fail", but the internal identifier associated with those values). 
You can refer to the JavaScript API documentation here: https://jazz.net/wiki/bin/view/Main/AttributeCustomization
Specifically https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript and https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Working_with_Enumerations

Comments
Maria Victoria Martinez Torino commented May 28 '14, 6:08 p.m.

Hi Brian,
Thanks for your prompt response.
I tried what you suggested but unfortunately that didn't work either.


Brian Fleming commented May 29 '14, 12:04 p.m.

Can you post your updated script?  This is working in my test environment. 

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.