Forums

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

Get value from Multi-Select Custom Field

Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2019

I am trying to write a behaviour using an IF statement. The condition being set on my Multi-Select Custom Field, named 'Skillset(s)'.

(PSUEDOCODE)

IF(Skillset(s).value == "Application Testing"){

*do something*

}

I have tried the usual methods of .value or .toString but I cannot find the correct method to access this field's value? Everything returns NULL, and then 'cannot evoke method on null object'.

 

How do I access the value of this field?? 

 

field.PNG

1 answer

1 accepted

0 votes
Answer accepted
Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2019

hello, because multiselect field returns you List of elements, you check it like this:

def skillSetsField = getFieldByName("Skillset(s)")
if ("Application Testing" in skillSetsField.value) {
  //do something
}
Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2019

Thanks for your response here is my code block. I'm not seeing the changes to my field or reaching my log statement in the if? 

 

 

def RiskLikelihoodField = getFieldByName("Risk Likelihood")
def skillSetField = getFieldByName("Skillset(s)")

if("Application Testing" in skillSetField.value){

log.debug("inside IF")

RiskLikelihoodField.setRequired(true)
RiskLikelihoodField.setHidden(false)
RiskLikelihoodField.setHelpText ("Risk Likeihood must be filled in once moved to 'Ready for Functional Testing'")
}

 

Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2019

here is my entire code block...It is logging my debug message inside the ELSE

import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.JiraWorkflow
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.DEBUG)

def issue = Issue
def issueManager = ComponentAccessor.getIssueManager()
def RiskLikelihoodField = getFieldByName("Risk Likelihood")
def skillsetField = getFieldByName("Skillset(s)")

def defaultValue = null


if ( "Application Testing" in skillSetField.value && getAction().id == "381") {

log.debug('inside IF')


RiskLikelihoodField.setRequired(true)
RiskLikelihoodField.setHidden(false)
RiskLikelihoodField.setHelpText ("Risk Likeihood must be filled in once moved to 'Ready for Functional Testing'")
}
else {
log.debug('inside else')
RiskLikelihoodField.setRequired(false)
RiskLikelihoodField.setHidden(true)
RiskLikelihoodField.setHelpText ("")
RiskLikelihoodField.setFormValue(defaultValue)
}

@Ilya Turov 

Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2019

is there anything in your logs? because I feel like it might silently fall on 

def issue = Issue

line hence doing nothing at all. I'd leave just this part and see if it works:

def RiskLikelihoodField = getFieldByName("Risk Likelihood")
def skillsetField = getFieldByName("Skillset(s)")

def defaultValue = null


if ( "Application Testing" in skillSetField.value && getAction().id == "381") {

log.debug('inside IF')


RiskLikelihoodField.setRequired(true)
RiskLikelihoodField.setHidden(false)
RiskLikelihoodField.setHelpText ("Risk Likeihood must be filled in once moved to 'Ready for Functional Testing'")
}
else {
log.debug('inside else')
RiskLikelihoodField.setRequired(false)
RiskLikelihoodField.setHidden(true)
RiskLikelihoodField.setHelpText ("")
RiskLikelihoodField.setFormValue(defaultValue)
}
Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2019

I removed said issue variable and I put a log in the ELSE as such...and the log returns a value of NULL for skillSetField.Value

def RiskLikelihoodField = getFieldByName("Risk Likelihood")
def skillSetField = getFieldByName("Skillset(s)")

def defaultValue = null

if ( "Application Testing" in skillSetField.value && getAction().id == "381") {

log.debug("skillSet Value " + skillSetField.value)

RiskLikelihoodField.setRequired(true)
RiskLikelihoodField.setHidden(false)
RiskLikelihoodField.setHelpText ("Risk Likeihood must be filled in once moved to 'Ready for Functional Testing'")
}
else {
log.debug('inside else')
//line below logs NULL value
log.debug("skillSet Value " + skillSetField.value)
RiskLikelihoodField.setRequired(false)
RiskLikelihoodField.setHidden(true)
RiskLikelihoodField.setHelpText ("")
RiskLikelihoodField.setFormValue(defaultValue)
}

@Ilya Turov  

Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2019

@Ilya Turov Also returning Null for 'getAction().id' when change the status

Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2019

do you have it in initializer or in a field script? Im not sure about the latter, but pretty sure it captured action during the initializer. are you sure your behaviour mapping is correct?

Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2019

I will keep plugging away, looks like you answered my initial question.

 

Thank you! 

Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2019

I hope at least that initial part is correct. 

Also, even though you are not getting action id for some reason, I think it should be a number, not a string (for future comparison). 

Like Judah likes this
Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 20, 2019

@Ilya Turov 

It looks like the problem is still with the Skillset(s) field value (the action ID check is working) but the line that you provided does not meet the comparison in my IF. 

def skillSetsField = getFieldByName("Skillset(s)")
if ("Application Testing" in skillSetsField.value) {
  //do something
}

When I log skillSetsField.value it remains NULL for some reason. ??

Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 20, 2019

are you positive the field exists? and that it's present on the screen

because if it's not on the screen, you need to use soemething like this:

def skillSetsField = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Skillset(s)")[0]
def skillSetsValue = underlyingIssue.getCustomFieldValue(skillSetsField)
if ("Application Testing" in skillSetsValue) {
//do something
}

e: because the first method only retrieves values from fields on the transition screen

Like Judah likes this
Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 20, 2019

ssf.PNGThe Skillset(s) field is under a tab called Categorize. 

Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 20, 2019

Working now! Thank you! 

Are tabs, such as the ones pictured above, considered part of the transition screen only if they are selected? ie. "story details" and "categorize" 

Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 20, 2019

no, transition screen is well, what it is, a transition screen, and it has nothing to do with view/edit/etc issue screens. and it can have it's own tabs

glad it worked in the end

Suggest an answer

Log in or Sign up to answer