It's all about the answers!

Ask a question

Disallow few combinations of an Enum List


Chidambaram L (23424390) | asked Aug 28 '15, 7:28 a.m.
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 ?

Accepted answer


permanent link
Donald Nong (14.5k614) | answered Aug 31 '15, 1:58 a.m.
edited Aug 31 '15, 2:00 a.m.
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

Comments
Chidambaram L commented Aug 31 '15, 1:20 p.m.

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 ?


Donald Nong commented Sep 03 '15, 9:20 p.m.

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
sam detweiler (12.5k6195201) | answered Aug 28 '15, 7:59 a.m.
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.

Comments
Chidambaram L commented Aug 28 '15, 8:42 a.m.

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.


sam detweiler commented Aug 28 '15, 9:12 a.m.

Yes, that is correct, dependant enum..

I do not know how to use dojo for this

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.