It's all about the answers!

Ask a question

How do I read custom text field based on the custom enumaration type using java script based.


Prasad Makkena (1716) | asked Jan 05 '18, 3:58 a.m.

Hi Team,

Using RTC version 6.0.2

I have added custom text field which type is "small String" and added custom enumeration list type.

My requirement is  when value select from enumeration drop down, text field should read the selected value from enumeration field.

Example: Enumeration type field A under have a, b, c, d etc values..
Note: We will be adding values in enumeration everyday basis. .
              
Text filed called B.

When i select value "a" in field A, Field B should read the selected value "a".

I saw this this information but it does not work for my requirement as we keep adding 100+ values every day basis.

Working with Enumerations

An enumeration is a special attribute type that allows an attribute to have one of a fixed predefined set of values called literals. When you define an enumeration you specify a name for each literal. Internally each literal is assigned a literal id. You can also manually configure this id in the process specification. When working with enumerations inside an attribute customization script you should use the literal ids to refer to literals and not their names. To see what the id for a literal is, open the process configuration source XML and look for the enumeration definition. Here is, for example, the configuration of the Severity enumeration:
<enumeration attributeTypeId="severity" name="Severity">
    <literal icon="processattachment:/enumeration/unassigned2.gif" id="severity.literal.l1" name="Unclassified"/>
    <literal icon="processattachment:/enumeration/minor.gif" id="severity.literal.l2" name="Minor"/>
    <literal default="true" icon="processattachment:/enumeration/normal.gif" id="severity.literal.l3" name="Normal"/>
    <literal icon="processattachment:/enumeration/major.gif" id="severity.literal.l4" name="Major"/>
    <literal icon="processattachment:/enumeration/critical.gif" id="severity.literal.l5" name="Critical"/>
    <literal icon="processattachment:/enumeration/blocker.gif" id="severity.literal.l6" name="Blocker"/>
</enumeration>
Please suggest if there is any other way.



Comments
Ralph Schoon commented Jan 05 '18, 4:56 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

What is the requirement? You describe a solution sketch that I don't understand. See How should I ask a question in the Forum if I want to receive useful answers?

Accepted answer


permanent link
Donald Nong (14.5k614) | answered Jan 07 '18, 7:28 p.m.

Although I don't truly understand your intent of duplicating an enumeration value to a string attribute, you should use the getLabel() function instead of getValue() to read the enumeration. For example, using the Enumeration definition that you quoted, getLabel() returns "Minor", while getValue() returns "severity.literal.l2".

But, I don't really see the benefit of using Enumeration if you keep adding 100+ values to it everyday. As Enumeration will be loaded into the editor as a full set most of the time, if you get an ever-increasing long list of enumerations, you will get severe performance issues very quickly. You'd better use a String attribute instead.

Prasad Makkena selected this answer as the correct answer

Comments
Prasad Makkena commented Jan 09 '18, 11:02 p.m.

Thanks a lot Donald, using getLable() able to read the enumeration whatever I selected.

For example If I select in enumeration as [aa bb cc] I should only read "aa" instead of entire [aa bb cc]

I think something wrong with my code, can you please help me here


Prasad Makkena commented Jan 09 '18, 11:03 p.m.

here is mu code

dojo.provide("com.example.programid");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {

 var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
 dojo.declare("com.example.programid",null, {
    getValue: function(attribute, workItem, configuration) {

   var ppmoprj;

            ppmoprj = workItem.getLabel("com.attribute.ppmoprj");
            var partialStr = ppmoprj.substring(2, ppmoprj.indexOf("]"));
            var res = partialStr.substring(0, partialStr.indexOf(" "));
            //var res = ppmoprj;
   return res;
    }
    });
})();

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.