Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to fetch the data of component using behaviour script runner

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 .

 

2 answers

0 votes
Hana Kučerová Community Leader Nov 09, 2020

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()
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

How to log work and track time in Jira when a person is part of multiple teams

  The manager’s daily activities include a list of challenges to reach high levels of efficiency for their teams. Part of these challenges is related to how to deal with the worklog systems sin...

68 views 2 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you