As i used validation on component (to select/restrict to one field only )
------------------------------------------------------------------------------
1st i tried this
import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.component.ProjectComponent
def component = getFieldById('components-textarea')
List <ProjectComponent> result = component.getFormValue() as List
if(result.size() >1)
{
component .setError("Only one Component is allowed")
}
else {
component.clearError()
}
------------------------------------------------------------------------------
2 ] I tried to get atleast size of selected element
def c = ComponentAccessor.componentClassManager.getMetaPropertyValues()
def component = getFieldById('components-textarea')
component.setHelpText("----->>Multi Select Field is set to Support " + c.size())
------------------------------------------------------------------------------
Help me to put validation on component field . My Requirement is to select only one field from System component field .
Hi @Nishant Paraskar ,
you are using incorrect id for components field, it should be "components" instead of "components-textarea".
Something like this should work:
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FormField
import static com.atlassian.jira.issue.IssueFieldConstants.COMPONENTS
FormField componentsField = getFieldById(COMPONENTS)
List<ProjectComponent> components = componentsField.getValue() as List
if (components.size() > 1) {
componentsField.setError("Only one Component is allowed")
} else {
componentsField.clearError()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Hana Kučerová thank you! Your code helpfull!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The code you provided is very effective, I use this method to get the name of component, but when I get the comment, I find that the comment information is not valid, here is my code, when I comment the definition of variable name, the last three lines of code are valid, if I do not comment, the last three lines of code are not valid. Can you help me see why, thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
test
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.