It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Jira PostFunction testing value of a checkbox custom field

Dave Marsico Nov 21, 2017

in Jira Software 7.4.2, trying to use PostFunction , to conditionally create a subtask, when a checkbox field has the value "Yes".

 

the condition I have scripted here is not matching the value "Yes"

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("Jira Log")
log.setLevel(Level.DEBUG)

log.debug("POSTFUNCTION DEBUG: test log")
log.debug("POSTFUNCTION DEBUG: " + issue)

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectByName("Update Global Webpage")
def cFieldValue = issue.getCustomFieldValue(cField)
log.debug("POSTFUNCTION DEBUG: " + cFieldValue)

if (! cFieldValue) {
log.warn ("Failed to find Update Global Webpage field on issue: ${issue.key}")
def result = false
return
}

def result = cFieldValue as String == 'Yes'

 

 

The output to the jira log is this

...  DEBUG dmarsico 843x581424x1 1r2alxr 10.82.178.50,0:0:0:0:0:0:0:1 /secure/WorkflowUIDispatcher.jspa [Jira Log] POSTFUNCTION DEBUG: test log
... DEBUG dmarsico 843x581424x1 1r2alxr 10.82.178.50,0:0:0:0:0:0:0:1 /secure/WorkflowUIDispatcher.jspa [Jira Log] POSTFUNCTION DEBUG: ET1-8
... DEBUG dmarsico 843x581424x1 1r2alxr 10.82.178.50,0:0:0:0:0:0:0:1 /secure/WorkflowUIDispatcher.jspa [Jira Log] POSTFUNCTION DEBUG: [Yes]

so it looks like the value is Yes,

I've tried 'Yes', "Yes"...

anyone see what I might be doing wrong here?  

 

 

1 answer

1 accepted

0 votes
Answer accepted
Alexey Matveev [cPrime] Community Leader Nov 21, 2017

Hello,

Do you mean that the result variable is always true? 

Dave Marsico Nov 22, 2017

what I mean is its not returning true for that test...

(so it doesn't create the subtask when I have that field = to Yes)

if I hardwire the return to true, it does create the subtask, so its seems it "would" work if the return value was true,  but I have yet to figure out why its not returning true in my example I've shown...

Alexey Matveev [cPrime] Community Leader Nov 22, 2017

I tried your code. It returns true if Yes and false if No.

Dave Marsico Nov 22, 2017

Alexey,

Thanks, ok i'm going to stare at things more...  As we cannot see what is going wrong here.  Appreciate you spending the cycles on this.

 

Dave

Dave Marsico Nov 27, 2017

Alexey,

 

thanks so in the end it turned out that due to this being a checkbox,  and returning in array format, i needed to test for '[Yes]'.

I'm all set now! thanks again.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Marketplace Apps & Integrations

Demo Den Ep. 4: Continuous Integration with CircleCI & Jira Software

Get ready! Demo Den Episode 4 is coming your way on Tuesday, May 28, 2018 with a Continuous Integration and Delivery special demo. CircleCI Director of Solutions Engineering, Eddie Webb will show us ...

486 views 0 4
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you