Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Setting custom field value by option id (select list)

Philip Kroos - TEAM XALT
Contributor
October 14, 2024

Dear community,

 

  • I have 2 projects (Project A and Project B) where the customfield_1 is set in Project A. 
  • customfield_1 is a Select List (single choice) and has two options. 
  • In Project B, I have customfield_2, which also is a Select List (single choice) with two options
  • I want to use an Automation to create a new issue in Project B and set customfield_2 based on the selection of customfield_1 in Project A using "Additional fields" and JSON, essentially mapping the values from one Select List 
  • In my initial tests I managed to do this by using conditional logic and the if-else statements, but I was only able to do so by typing the option of the customfield_1, which might be changed by other administrators in its exact wording.

I used something like

 

"customfield_2": { "value": "{{#if(equals(triggerIssue.fields.customfield_1.value, "Option 1 name in Project A"))}}Option 1 Name in Project B{{/}}{{#if(equals(triggerIssue.fields.customfield_2value, "Option 2 name in Project A"))}}Option 2 Name in Project B{{/}}"

 

Is there a way to reference the options of a custom field based on the option id instead of their name? I know how to find the option id in the custom field settings but I don't know how to do the mapping and didn't find yn documentation

If anyone has a clue, please let me know :)

 

 

 

 

3 answers

3 votes
Bill Sheboy
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.
October 14, 2024

Hi @Philip Kroos - TEAM XALT 

Yes, and...to the other suggestions offered:

I recommend using a lookup table rather than conditional logic to translate the field value.  That will be easier to maintain / debug in the rule.  Please look here to learn more about lookup tables:

https://community.atlassian.com/t5/Automation-articles/Update-Create-lookup-table-action-improvements/ba-p/2427798

Kind regards,
Bill

2 votes
Samuel Gatica _ServiceRocket_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 14, 2024

HI @Philip Kroos - TEAM XALT 

To reference the option ID in the field you can use the following smart value:

{{issue.CUSTOM_FIELD.id}}

 

Best regards

Sam

2 votes
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 14, 2024

Hi @Philip Kroos - TEAM XALT --

I think this should work:

"customfield_2": { "id": "{{#if(equals(triggerIssue.fields.customfield_1.id, "optionId-1-a"))}}optionId-1-b{{/}}{{#if(equals(triggerIssue.fields.customfield_2.id, "optionId-2-a"))}}optionId-2-b{{/}}"

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 14, 2024

Documentation for Advanced Field Editing for Single-select custom fields:

Select a single value from a defined list of values. You can address them by value or id.

"customfield_11449" : { "value": "option3" }

or

"customfield_11449" : { "id": 10112 }
Philip Kroos - TEAM XALT
Contributor
October 17, 2024

Hi @Darryl Lee , I agree, this should work, yet it doesn't :(

My formula is currently 

"customfield_10632":
{ "id": "{{#if(equals(triggerIssue.fields.customfield_10633.id, "11392"))}}11390{{/}}{{#if(equals(triggerIssue.fields.customfield_10633.id, "11393"))}}11391{{/}}"

 

  • customfield_10632 equals customfield_2 in Project B.
    • 11390 equals optionId-1-b in Project B (since this is where customfield_10632 is).
    • 11391 equals optionId-2-b in Project B (same as above).
  • customfield_10633 equals customfield_1 in Project A.
    • 11392 equals optionId-1-a in Project A (since this is where customfield_10633 is).
    • 11393 equals optionId-2-a in Project A.

 

In other words, the mapping is as follows:

 

  • When customfield_10633 in Project A has option ID 11392, set customfield_10632 in Project B to option ID 11390.
  • When customfield_10633 in Project A has option ID 11393, set customfield_10632 in Project B to option ID 11391.

Maybe I'm missing something obvious but the formula should work

Bill Sheboy
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.
October 17, 2024

Hi @Philip Kroos - TEAM XALT 

Context is important for automation rule questions, so without seeing your complete rule and where that expression is used, diagnosis is challenging.

One thing is certain: please note you have nested the double-quotation marks in the expression, and so that is unlikely to evaluate correctly.  The workaround for that would be to determine the id value, saving it to a variable, and then use that variable in the JSON expression.

Kind regards,
Bill

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 17, 2024

@Bill Sheboy speaks the truth about nested double-quotes. I missed that. And yes, screenshots would helpful here.

ALSO helpful: Audit logs.

You can put the full expression into an Audit log, but you also should put pieces of it, like:

{{triggerIssue.fields.customfield_10633.id}}

and 

{{#if(equals(triggerIssue.fields.customfield_10633.id, "11392"))}}11390{{/}}

I wonder too if maybe Automation might treat option ID as an integer, then maybe you could skip the quotes altogether and use eq instead of equals? This is a BIG IF:

{{#if(triggerIssue.fields.customfield_10633.id.eq(11392))}}11390{{/}}
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 17, 2024

OR, I'm an idiot and didn't read the docs I quoted:

"customfield_11449" : { "id": 10112 } 

You don't need quotes around the option ID. So you want this:

"customfield_10632":
{ "id": {{#if(equals(triggerIssue.fields.customfield_10633.id, "11392"))}}11390{{/}}{{#if(equals(triggerIssue.fields.customfield_10633.id, "11393"))}}11391{{/}} }

(I removed the quotes around the ID, and added a closing brace that you missed.

Philip Kroos - TEAM XALT
Contributor
October 28, 2024

Hi @Darryl Lee , in the end we decided to not use ids but values, this makes the automation work. However, if we don't fill the field for customfield_10633, the automation doesn't work ("Error creating issue Specify a valid value for NAME (customfield_10632)")

I tried {{#if(equals(triggerIssue.fields.customfield_10633.value,NULL))}}{{/}} but this doesn't work and still gives me the same error message. Basically, if customfield_10633 is empty, customfield_10632 should also remain empty when creating a new issue

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 28, 2024

Hi @Philip Kroos - TEAM XALT -

I'm wondering if you could add an IF block that checks if {{triggerIssue.fields.customfield_10633}} is EMPTY before it even attempts to do the Edit.

Screenshot 2024-10-28 at 9.45.48 AM.png

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events