How to set a single user picker cf via nunjucks?

We set some CFs via JMWE post actions, in general it´s working fine. But for a single user picker CF we got some problems, although logs do not contain anything.

From a functional perspective we want to check the reporter, and based on this value we want to set the field "Supervisor" with another user.

{% set reporter = issue.fields.reporter.name %}
{% set supervisor = issue.fields.Supervisor.name %}
   
        {% if reporter == hhunfeld %}
            {% set supervisor = mkallage %}
		{% elif reporter == mfichtner %}
			{% set supervisor = mkallage %}	
		{% elif reporter == bbruese %}
			{% set supervisor = hhunfeld %}
		{% elif reporter == dnienaber %}
			{% set supervisor = hhunfeld %}
		{% elif reporter == upaucker %}
			{% set supervisor = hhunfeld %}
  
		{% else %}
			{% set supervisor = mkallage %}
        {%endif%}

Tried also with issue.fields.Supervisor.displayName, but also no success. What is wrong here, i´m no coder so it would be great if anybody can jump in and help me a bit...

Many thanks,

Hans-Hermann

1 answer

1 accepted

Hi Hans-Hermann,

you need to enclose string constants in double quotes (e.g. "hhunfeld") in your "if" and "set" statements. You also need to eventually print a value out. Try:

{% set reporter = issue.fields.reporter.name %}

        {% if reporter == "hhunfeld" %}
            {% set supervisor = "mkallage" %}
        {% elif reporter == "mfichtner" %}
            {% set supervisor = "mkallage" %}
        {% elif reporter == "bbruese" %}
            {% set supervisor = "hhunfeld" %}
        {% elif reporter == "dnienaber" %}
            {% set supervisor = "hhunfeld" %}
        {% elif reporter == "upaucker" %}
            {% set supervisor = "hhunfeld" %}
        {% else %}
            {% set supervisor = "mkallage" %}
        {%endif%}
{{ supervisor }}

Note that there is also a shorter way:

{% set reporter = issue.fields.reporter.name %}

        {% if reporter == "hhunfeld" %}
            mkallage
        {% elif reporter == "mfichtner" %}
            mkallage
        {% elif reporter == "bbruese" %}
            hhunfeld
        {% elif reporter == "dnienaber" %}
            hhunfeld
        {% elif reporter == "upaucker" %}
            hhunfeld
        {% else %}
            mkallage
        {% endif %}

Hey David,

many thanks, your quick reply is working as expected!

Damn, it should have noticed this by myself as well... sad

You're welcome.

I modified my reply, you don't need the "Ignore empty value" since you have an "else" statement. But if you wanted to leave the existing value of the Supervisor field untouched when the reporter didn't match any of your "if" statements, you would simply remove the "else" and check the "Ignore empty value" option.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,760 views 11 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot