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

Disallow few combinations of an Enum List

I have an Enumuration List Attribute (multi-select). Say the values are A,B,C,D&E.
How do I disallow few permutations like (when A is choosen, no other values are allowed; B,C,D&E cannot be allowed as a combination).
Will a script based validation help ?

0 votes


Accepted answer

Permanent link
Yes you can use a script based validator to do that, but the implementation can be a bit complicated. First use the workItem.getValue() function to retrieve the current values of the attribute. This will be an array of JavaScript objects, with each containing four attributes - _eQualifiedClassName, iconUrl, id and label (you will be interested in the last two only). Loop through the array and process the labels - you can put them into a "Set" for easy access. Evaluate the chosen values, and return Status.OK_STATUS or a new error depending on the condition. The main body of the function will look like this.
    var enumList =  workItem.getValue("enumList");
    var enumSet = new Set();
    for (var i=0; i<enumList.length; i++)  {
        enumSet.add(enumList[i].label);
    }
    console.log("enumSet: " + enumSet);
    if (enumSet.has("A") && enumSet.size>1)  {
        return new Status(Severity["ERROR"], "When A is chosen, no other values are allowed");
    } else if (enumSet.has("B") && enumSet.has("C") && enumSet.has("D") && enumSet.has("E"))  {
        return new Status(Severity["ERROR"], "B, C, D&E are not allowed as a combination");
    } else {
        return Status.OK_STATUS;
    }

Chidambaram L selected this answer as the correct answer

0 votes

Comments

Thanks for the detailed explanation and the script.
Where will console.log write to; is it the Tomcat console that opens at the time of starting the application ?

Depending on which client you are using, but it will not appear in the Tomcat console or the catalina.out file.
If you are using RTC Eclipse client, the message will appear in the .metadata/.log file under the Eclipse workspace.
If you are using a browser, the message will appear in the web console.
If the script is executed on the server side, the message will appear in the .metadata/.log file under the CCM Eclipse workspace (for example, $JAZZ_HOME/server/tomcat/work/Catalina/localhost/ccm/eclipse/workspace/.metadata/.log). Note that execution errors will appear in ccm.log as well so you need to check this file when debugging the script.


One other answer

Permanent link
the RTC UI design is to allow all changes, then reject them on submit. There is very limited support for interactive content access. The only one I know of is the tree view value set, where selecting one in column A will enable a subset of the entries in column B.

0 votes

Comments

By tree view value set, I believe you are referring to Dependent Enum, where 2 Enum attributes will be defined.
In my requirement, one enum att is only allowed. One rule states that maximum of 3 values can be choosen.
Can you also guide me on how to access the attribute value of an Enum list in dojo script.

Yes, that is correct, dependant enum..

I do not know how to use dojo for this

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
× 10,940

Question asked: Aug 28 '15, 7:28 a.m.

Question was seen: 3,023 times

Last updated: Sep 03 '15, 9:20 p.m.

Confirmation Cancel Confirm