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

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

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

0 votes



One answer

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

0 votes

Comments

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

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

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,121

Question asked: May 28 '14, 3:09 p.m.

Question was seen: 4,890 times

Last updated: May 29 '14, 12:04 p.m.

Confirmation Cancel Confirm