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??
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
}
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'")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ilya Turov Also returning Null for 'getAction().id' when change the status
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I will keep plugging away, looks like you answered my initial question.
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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. ??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The Skillset(s) field is under a tab called Categorize.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.