It's all about the answers!

Ask a question

Attribute Customisation: Setting a Custom Attribute (enumerated) using a Calculated Value script


Ian Cuttriss (155) | asked May 16 '14, 8:32 a.m.
edited May 16 '14, 10:23 a.m. by Ralph Schoon (60.5k33643)
We have added a custom attribute ("Risk RAG") to the Risk work item. The attributed is an enumerated type with possible values of "Red", "Amber" and "Green". We are attempting to set the value using a script which utilizes the "Exposure" attribute. Here is the script code:
dojo.provide("risk.rag.ValueProvider");
(function() {
    dojo.declare("risk.rag.ValueProvider", null, {
        getValue: function(attribute, workItem, configuration) {
            var riskrag = "Unassigned";
            var exposure = 0;
            var redrag = 59;
            var amberrag = 17
            var greenrag = 1
            var exposure = workItem.getValue("com.ibm.team.workitem.workItemType.risk.exposure");
            if (exposure > redrag) {
                riskrag = "Red";
            } else {
                if(exposure > amberrag){
                    riskrag = "Amber";
                } else {
                    riskrag = "Green";
                }
            }                    
            return riskrag;
        }
    });
})();
When the attribute is displayed in the work item editor and error ("The selected value is not applicable") is displayed next to the attribute. I suspect that this is due the fact we have not assigned the enumerated literal correctly.
Please can you advise on how I retrieve and set the enumerated literal within the Calculated Value script.

Many thanks

2 answers



permanent link
sam detweiler (12.5k6185201) | answered May 16 '14, 9:07 a.m.
what are the ID's of your enum values?  ID's are what u need to manipulate.

I don't know how to retrieve the enum value IDs via javascript.

permanent link
Eric Jodet (6.3k5111120) | answered May 16 '14, 9:08 a.m.
JAZZ DEVELOPER
 Hello Ian,
you're correct. You should not use enum values labels (Red, Amber, ...)
but fully qualified id's (myenum.id.literal.l2, etc...)
See https://jazz.net/wiki/bin/view/Main/AttributeCustomization#WorkingWithEnums

To map id to label, check Project Area Source.

Hope it helps.
Eric

Comments
Ian Cuttriss commented May 16 '14, 9:19 a.m.

Eric, many thanks for the pointer. Once I have the Id's how do I return the correct value?


sam detweiler commented May 16 '14, 9:23 a.m.

how does he get the enum shape? literal id ='text string' so that his code is not dependent on the last time he manually read the process config source.


sam detweiler commented May 16 '14, 9:31 a.m.

you return the id string (for example) 'com.ic.risk.exposure.enum.green'

ic= your initials


Ian Cuttriss commented May 16 '14, 11:48 a.m.

Thank you for the pointer. All now working.

Your answer


Register or to post your answer.