Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner behaviours not honoring Required for my "select list" on my service desk

Crystal Gummo
June 1, 2018

Has anyone else run into this problem?

  • I've got a request type in a Jira Service Desk with a Project select list that I want to be optional by default (so it can receive email) but when a user is using the service desk portal, I want the Project select list to be required.
  • I set up ScriptRunner Behaviours to make the Project select list required on the service desk portal.  I know it's configured correctly because the "(optional)" note is gone from the field since I set up the Behaviour.  However, I can still submit a ticket without selecting something in the Project list (by leaving it as "none").

The only thing I can think is that Behaviours is seeing the "none" option selected in the Project select list as a viable option, instead of not one of the real options at all.

Note: "none" is not one of the options configured for the select list.  It's only showing up because we don't want to set a default value for this particular select list so Jira puts a "none" in the select list for you when the form first loads.

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
March 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

Ricardo Cardoso D_ Oliveira
Contributor
March 17, 2021

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()
}
}
}
}
Ricardo Cardoso D_ Oliveira
Contributor
March 19, 2021

Hi Ram,

 

I solved the problem with this line:

 

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

 

Thanks for the help!

 

Ricardo D'Oliveira

TAGS
AUG Leaders

Atlassian Community Events