Forums

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

How can I append multi-select list with automation

Sean C-S October 23, 2024

Hi

I am testing an automation that populates categories (a multiselect list) field based on input in another multiselect list.

The automation includes a lookup table to determine the categories to apply with the last step adding values to the category field using the following advanced edit:

 

{ "update": { 
"customfield_12345": [{
"add": {
"value": "{{CategoryInput}}"
}
}]
}
}

The rule runs successfully however the edit step replaces all values in the custom field rather than append the list. 

I assume this is due to how I have written the advanced edit. 

Can someone offer some guidance please?

Screenshot of automation flow below:

2024-10-23_09h21_03.png

3 answers

1 accepted

2 votes
Answer accepted
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 23, 2024

Hi @Sean C-S -- Welcome to the Atlassian Community!

To clarify your scenario a bit, are you trying to copy values from one multiple-selection option field to another multiple-selection option field, perhaps translating the values in the process?

If so, your rule cannot use a branch to do so.  The reason is branches which could be on more than one thing are run in parallel and asynchronously.  And thus each pass through the loop will "walk over" the prior results, but in no particular ordering.

Instead you could use list iteration to pre-build the JSON needed in Create Variable, and then perform a single Edit Issue action with that variable.

Kind regards,
Bill

Sean C-S October 23, 2024

Hi @Bill Sheboy 

Thanks for the response.

Your assumption is correct, the values are translated from on multi-select to another multi-select. 

I have followed your advice and have removed the branching. My edit action now looks like this:

{
"update": {
"customfield_12345": [
{
"set": [
{{#customfield_67890}}
{{#if(ClientCategory.get(value))}}
{
"value": "{{ClientCategory.get(value)}}"
}{{^last}},{{/}}
{{/}}
{{/}}
]
}
]
}
}

 The behaviour is different now, it appears to always set customfield_12345 to empty.

I added some log actions to see what was happening:

  • It correctly
    • understands all inputs from customfield_67890
    • evaluates {{ClientCategory.get("key")}} where "key" has manually been typed into the log action
    • display all inputs in a log action like this: 
      {{#customfield_67890}}Direct mapping for value {{value}}: {{ClientCategory.get(value)}}{{/customfield_67890}}
  • It does not
    • provide any output for the last mentioned log above

It seems as though the inputs are working, but when passed to the "ClientCategory.get(" they are passed as empty. This is reinforced by the fact if I remove the if statement, I get an error at the edit step which states that Option value '' is not valid (customfield_12345).

Any ideas?

Thanks again,

Sean

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 23, 2024

Unfortunately, you may not use the lookup table for this scenario either.  The reason is once inside of an iterator, no other data is accessible from outside.  And so when you iterate over customfield_67890's value the lookup table cannot be accessed.

 

Instead you will need to use a series of conditional expressions.  Let's assume you want to replace the values in customfield_12345, and so this would work:

{
"fields": {
"customfield_12345" : [
{{#customfield_67890}}
{ "value":
{{#if(equals(value,"valueA")}} "replacement of valueA" {{/}}
{{#if(equals(value,"valueB")}} "replacement of valueB" {{/}}
{{#if(equals(value,"valueC")}} "replacement of valueC" {{/}}
} {{^last}}, {{/}}
{{/}}
]
}
}

 If you wanted to add the values instead, use the "update" syntax with "add".

Sean C-S October 24, 2024

Thanks @Bill Sheboy 

I managed to get this working with some tweaks. 

For any future visitors, this is what worked for me:

  1. Automation Trigger -> When value changes for customfield_67890
  2. Edit -> advanced:
{
"fields": {
"customfield_12345": [
{{#customfield_67890}}
{{#if(equals(value,"valA"))}}{ "value": "replacement of valA" }{{/}}
{{#if(equals(value,"valB"))}}{ "value": "replacement of valB" }{{/}}
{{#if(equals(value,"valC"))}}{ "value": "replacement of valC" }{{/}}
{{^last}},{{/last}}
{{/customfield_67890}}
]
}
}

 

Like Bill Sheboy likes this
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 24, 2024

Well done! 

I almost suggested that approach, but erred on the side of removing any redundancy in the dynamic JSON building (and so extracted the "value" parts outside the conditional checks).  I wonder: does your field contain any values other than "valA", "valB", or "valC"?  If so, that could explain why my version did not work as expected.

Like Sean C-S likes this
Sean C-S November 4, 2024

Yes it does.
Thanks again for the guidance, it works perfectly now :)

Like Bill Sheboy likes this
0 votes
SUVARNA Dixit February 27, 2025

 2 controls of Multiple selection dropdown 

List A holds values such as (Winter, Summer)

List B -should Auto-populate on the basis of items from List A (List B holds list of fruits)

Winter =Grapes,Oranges  

Summer =Mangoes,Watermelon

In detail , if user is selecting Winter from List A then, list b should be populate Grapes, Oranages 

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.
February 27, 2025

Hi @SUVARNA Dixit 

Are you asking a new question?

If so, please create a new one using the "Ask a question" link at the top of this page...rather than adding on to this already resolved one.

Kind regards,
Bill

0 votes
Marios Marneros
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 23, 2024

Hey @Sean C-S , welcome to the Atlassian Community.
In the Edit request you will need to include the existing field value as well as the new value you want to add in the multiselect for it to be added and not replace the existing value.

Let me know if that works and I can support you to troubleshoot the automation.

Sean C-S October 23, 2024

Hi @Marios Marneros 

Thanks for answering.

I'm not sure how I can achieve that in the branch since 1 - n values could be added.

Do i need to create a list (array I think) of all the values that are added and then add it in bulk maybe?

Thanks

Sean

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events