Forums

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

checkbox as filter in ScriptRunner script

helen levich
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 26, 2019

Custom field checkbox "Merge" set to have only one value "Yes". So, practically when checkbox is not set to yes, then it does not show on story.
I need to set filter to when checkbox is not equal to "Yes"
I tried
if( it.toString() != "Yes")
if( it.toString().empty)
if( it.toString() != "")
if( it.toString() != null)

if (it.toString().trim().length() == 0)

Nothing works. Does anyone have a suggestion?

This works fine with filter set to Merge=Yes.

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Merge");
def checkBoxValue = issue.getCustomFieldValue(customField)
checkBoxValue.each
if( it.toString() == "Yes")

 

 

Thank you

2 answers

1 accepted

0 votes
Answer accepted
PD Sheehan
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 26, 2019

getCustomFieldValue on a checkbox field returns an array of options.

You can check that with:

def customField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Merge")
def checkBoxValue = issue.getCustomFieldValue(customField)
log.info "checkboxValue is of type ${checkBodValue.getClass()}"

So to know if "Yes" is checked or not try this:

def customField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Merge")
def checkBoxValue = issue.getCustomFieldValue(customField)
def yesIsChecked = checBoxValue.any{it.value == 'Yes'} //will be True or False
helen levich
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 26, 2019

Thank you. I made change, but it still does not work. could you please suggest?

 

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Incremental Dev Merge");
def checkBoxValue = issue.getCustomFieldValue(customField)

checkBoxValue.each
{
log.warn "================check box: "+it.toString()
log.warn("================issueLink.issueLinkType.name: "+issueLink.issueLinkType.name)

def yesIsChecked = checkBoxValue.any{it.toString() == 'Yes'}

if(issueLink.issueLinkType.name == "Epic-Story Link" && issue.getIssueType().name == "Story" && yesIsChecked == false)

{
def currentValue = epicissue.getAffectedVersions()

PD Sheehan
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 27, 2019

Can you post your full code in a properly formatted code block? At the very least, there is a missing closing }. It's hard to know what else might be missing.

But at first glance ... "it.toString()" should be "it.value" or "it.getValue()"

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Incremental Dev Merge");
def checkBoxValue = issue.getCustomFieldValue(customField)

checkBoxValue.each {
log.warn "================check box: $it.value"
log.warn("================issueLink.issueLinkType.name $issueLink.issueLinkType.name")
}
def yesIsChecked = checkBoxValue.any{it.value == 'Yes'}

if(issueLink.issueLinkType.name == "Epic-Story Link" && issue.issueType.name == "Story" && !yesIsChecked)
{
def currentValue = epicissue.getAffectedVersions()
}
Like helen levich likes this
helen levich
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 27, 2019

Thank you, that works. :)

0 votes
Tomasz Bryła
Contributor
August 26, 2019

Hi @helen levich

Try this,

If(!issue.getCustomFieldValue(customfield))

{

//Do something

}

helen levich
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 26, 2019

Thank you, I tried it, but for some reason it does not work.

Suggest an answer

Log in or Sign up to answer