Possible to enforce subcategory selection?
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
Comments
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.
1 vote
Thanks Ralph. Since it is only a single node category that I am concerned with, would the javascript work with a hardcoded label check?
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.
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;
}
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
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;
}