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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,555,440
Community Members
 
Community Events
184
Community Groups

Behaviour - Limit options on multi-select field (Elements Connect (nFeed))

Hello guys!

I am using a Behavior for a Multi-select custom field from Elements Connects (nFeed) so that, in some projects, it is possible to select only one option from the various ones available.

Behavior works perfectly on the editing screens, however, I was unable to make it work on the issue creation screen.

Here is the code:

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import groovy.json.*

@BaseScript FieldBehaviours fieldBehaviours

def projectKey = underlyingIssue.getProjectObject().key
def cfSigla = getFieldById("customfield_10301")
def cfSiglaValue = cfSigla.getValue().toString()
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText(cfSiglaValue)

assert object instanceof Map
assert object.inputValues instanceof List

if(projectKey != 'SPAC'){
if(object.inputValues.size() > 1){
cfSigla.setError("error message.")
}else if (object.inputValues.size() <= 1){
cfSigla.clearError()
}
}

 

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Mar 16, 2021

Hi Ricardo,

To answer your question, this is the expected behaviour.

In your code, you are acquiring the projectKey by using the underlyingIssue.  The underlyingIssue is only accessible after the issue is created. Hence, it will not work on the Create screen.

To invoke the Behaviour for both the Create and Edit screen, you could try something like this:-

import com.atlassian.jira.component.ComponentAccessor

def projectManager = ComponentAccessor.projectManager
def projectObjects = projectManager.projectObjects

projectObjects.find {
if(it.key != "SQ") {

if(underlyingIssue == null) { // Invoked during the Create screen

log.warn "====>>> Project Invoked During Creation ${it.key}"

} else { // Invoked during Edit screen

log.warn "===>>>> Project Invoked During Editing ${it.key}"
}
}
}

Please note this sample code is not 100% exact to your environment. Hence you will need to make the required modifications.

In this example, instead of using the underlyingIssue, I am using the ProjectManager's projectObjects to find the project key.

I hope this helps to solve your question :)

Thank you and Kind Regards,

Ram

Hi Ram!

Thanks for your reply!

 

I tried to implement your suggestion on my code, but, still not working during Create Screen 

 

Here is my new code:

 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import groovy.json.*

@BaseScript FieldBehaviours fieldBehaviours

def projectManager = ComponentAccessor.projectManager
def projectObjects = projectManager.projectObjects
def cfSigla = getFieldById("customfield_10301")
def cfSiglaValue = cfSigla.getValue().toString()
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText(cfSiglaValue)

assert object instanceof Map
assert object.inputValues instanceof List

projectObjects.find {
if(it.key != "SPAC") {

if(underlyingIssue == null) { // Invoked during the Create screen
if(object.inputValues.size() > 1){
cfSigla.setError("error message.")
}else if (object.inputValues.size() <= 1){
cfSigla.clearError()
}

} else { // Invoked during Edit screen
if(object.inputValues.size() > 1){
cfSigla.setError("error message.")
}else if (object.inputValues.size() <= 1){
cfSigla.clearError()
}
}
}
}

Hi Ram,

 

I solved the problem with this line:

 

def projectKey = issueContext.getProjectObject().getKey()

 

Thanks for the help!

 

Ricardo D'Oliveira

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events