It's all about the answers!

Ask a question

Possible to enforce subcategory selection?


Sian O'Briain (35821) | asked Apr 08 '16, 12:13 p.m.
edited Apr 08 '16, 12:15 p.m.
We are using RTC Version 5.0.2, and "Filed Against" is a mandatory attribute.

Picture the following scenario:

root(unassigned)
       ->ParentCat
               ->ChildCat1
               ->ChildCat2

Is it possible to enforce selection of one of the Child Categories here? I know not allowing selection of the parent category defeats the purpose of having the parent category at all but it would make life easier :)

One answer



permanent link
Donald Nong (14.5k414) | answered Apr 15 '16, 2:16 a.m.
It should be quite easy to do with a validator (attribute customization). Just read the value of the attribute and test with the two child categories, and return true or false accordingly.

Comments
1
Ralph Schoon commented Apr 15 '16, 2:26 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

JavaScript: How would you test for the category to be a leaf or not? The only information you have is the label and the value and no API to look into the category tree.

Java: Yes, you could use a validator, but that needs to be deployed on clients and servers.

A work item save precondition only needs to be deployed on the server so it might be a better approach. It lacks the user guidance though.


Sian O'Briain commented Apr 15 '16, 4:46 a.m.

Thanks Ralph. Since it is only a single node category that I am concerned with, would the javascript work with a hardcoded label check?


Ralph Schoon commented Apr 15 '16, 4:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I think you have to try out what you get for workItem.getLabel( WorkItemAttributes.FILED_AGAINST ) and workItem.getValue( WorkItemAttributes.FILED_AGAINST )and if you can use any of that to decide.


Sian O'Briain commented Apr 15 '16, 11:25 a.m.

yay I got it working with a validation script:

validate: function(attribute, workItem, configuration) {
       
        var category = workItem.getValue(attribute);
       
        if(category == "[category_id]"){
          return new Status(Severity["ERROR"], "Validation failed");
        }

return Status.OK_STATUS;

        }



Sian O'Briain commented Apr 15 '16, 3:41 p.m.

For a more general case of blocking all category nodes - the getLabel function returns a string with three spaces pre-pended per level (e.g. subCat1 has three spaces before the title, subCat2 has 6 spaces before the title). However of course this would only be relevant / useful if you have just 2 levels of categories


Sian O'Briain commented Apr 15 '16, 3:43 p.m.

example:

validate: function(attribute, workItem, configuration) {
       
        var category = workItem.getLabel(attribute);       
        var substring = "   ";
        var ind = category.indexOf(substring);
        if(ind != -1){
          return new Status(Severity["ERROR"], "Validation failed - you can not choose parent category: ".concat(category));
        }

return Status.OK_STATUS;

        }

showing 5 of 6 show 1 more comments

Your answer


Register or to post your answer.