Checking value of custom field to set value of another

I am attempting to use a custom Post Function in a workflow to translate a String value to a numerical value. I have created a Custom Field named Size with five possible values:

  • One hour or less.
  • About two hours of work.
  • About half a day.
  • A full day's work.
  • About two to three days.

These are the basic sizes my team can use to estimate the size of tasks. Newly created tasks are Unestimated. In order for them to move to Open, they must first be Estimated. The Estimate transition displays a window with the Size dropdown. My goal is to have this string be converted to a pre-set value that populates the Story Points field.

In the Post Function I have added the following, using Update parameters of the Set Field Value (JMWE add-on) function:

{% if issue.fields.size == "One hour or less." %}
    1
{% elif issue.fields.size == "About two hours." %}
    2
{% elif issue.fields.size == "About half a day." %}
    4
{% elif issue.fields.size == "A full day's work." %}
    8
{% elif issue.fields.size == "About two to three days." %}
    16
{% else %}
    3
{% endif %}

 

I entered 3 as a unique identifier for the ELSE state, and it is being passed through correctly to the Story Points field, but I am not sure why the other IF checks are failing.

 

 

 

1 answer

1 accepted

I figured it out. I needed to call the unique ID, not the name, of the custom field, and pull the Value of that field, using the following code:

 

{% if issue.fields.customfield_11300.value == "One hour or less." %}
    1
{% elif issue.fields.customfield_11300.value == "About two hours." %}
    2
{% elif issue.fields.customfield_11300.value == "About half a day." %}
    4
{% elif issue.fields.customfield_11300.value == "A full day's work." %}
    8
{% elif issue.fields.customfield_11300.value == "About two to three days." %}
    16
{% else %}
    0
{% endif %}

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

788 views 2 19
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you