Add a list of assets to an asset objects list field
Asked by Luka Urushadze:

Hello everyone,

I have a custom field - Select List (multiple choices) and from this custom field I want to fill in an Assets objects custom field which can hold multiple objects. With automations, I was only able to edit the field and add one value - with advanced branching for each value, it simply overwrites the previous one so in the end I always have a single value in the field. Any ideas on how I can maybe attend a value instead of setting it?


Answers:
author: Franti?ek ?pa?ek _MoroSystems_
body: Hi [@Luka Urushadze](/t5/user/viewprofilepage/user-id/5439595)

I am not sure what your query to the Asset database is, but my guess is that it returns single object everytime? If so, is it maybe possible to use just one Lookup with combined query to search for all objects altogether? I can help you with that, but I will need a little bit more info about the original multiple select and how do you translate those values selected to assets query.

If so, then you can really shorten this automation to two actions:

1. Lookup objects
2. Edit issue

Once you get the Lookup Objects to return all objects you need, you can then simply use "Edit issue" action, select field you want to edit, and put this inside:

```
Key IN ({{#lookupObjects}}"{{.}}"{{^last}}, {{/}}{{/}})
```

This will ensure all returned objects are stored in your multi picker assets field.

Have a nice day!

comments: author: Luka Urushadze
body: Hello Franti?ek,

that'd be fantastic - the select field holds the labels of the objects. I couldn't think of a way to look up all values from the select list at the same time. Could you advise how I could do that?

Best Regards,

Luka Urushadze


author: Franti?ek ?pa?ek _MoroSystems_
body: Hi [@Luka Urushadze](/t5/user/viewprofilepage/user-id/5439595)

could you please provide us any example? What does the values in the multi select look like and what does a single object in your databse look like, so I can help you with the query?


author: Luka Urushadze
body: Thanks! Here's the values of the select field as an example, and one of the assets. It's a list of countries actually.

Field values:

![Screenshot 2024-08-14 at 18.59.01.png](https://community.atlassian.com/t5/image/serverpage/image-id/341802i8D9AA3E570BAD4B1/image-size/large?v=v2&px=999 "Screenshot 2024-08-14 at 18.59.01.png")

Asset Object:

![Screenshot 2024-08-14 at 19.00.27.png](https://community.atlassian.com/t5/image/serverpage/image-id/341803iE464B7B64EC53929/image-dimensions/315x248?v=v2 "Screenshot 2024-08-14 at 19.00.27.png")


author: Franti?ek ?pa?ek _MoroSystems_
body: Ok, that should be fairly easy - I see that you can search by label for assets, so I would do something like this (for having it well aranged and debugable for the future).

After trigger will follow these actions:

1. Create variable
   1. Put whatever name you want there (e.g. countries - so the resulting smart value will be {{countries}})
   2. Smart value will be like this:
   3.

      ```
      {{#issue.Field}}"{{.}}"{{^last}},{{/}}{{/}}
      ```

   4. Replace "Field" by the name of your multi select custom field. This will create variable, that will create list of values, from your example it should generate "DE", "FR", "IT", "ES"
2. Log action and just put {{countries}} in there - just to be sure you've got correct variable in the audit log. It should print "DE", "FR", "IT", "ES" to the Audit log when rule is executed.
3. Lookup issues
   1. Set the scheme you want to search in.
   2. AQL will be:
   3.

      ```
      label IN ({{countries}})
      ```

   4. This should return all objects, 4 in your example (assuming that all exists in Assets database and have correct names).
4. You can add another "Log action" here and just put "{{lookupObjects}}" there, again just to see what is happening.
5. Last will be Edit issue action.
   1. Select Assets field you want to edit and put this into it:
   2.

      ```
      Key IN ({{#lookupObjects}}"{{.}}"{{^last}}, {{/}}{{/}})
      ```

And this is it.

Obviously "Log action" steps are optional, but I always recommend printing at least some variable from within the automation to the audit log. In case it fails somewhere from time to time, it will be much easier for you to see what happened. E.g. you will add new option to the select, but forget to add new value to the assets too. That might result in lookupObjects being empty.

Also one last note: I am not sure what your process is, but why won't you let people use that asset field directly? Thats probably the biggest advantage of the whole assets - to be able to select from them. Even on the customer portal or anywhere. Here you are basically just duplicating things.

Have a nice day!


author: Luka Urushadze
body: Hi Franti?ek,

thanks a lot, that saved my day! It worked perfectly and was exactly what I was looking for.

I couldn't use the asset fields directly as the flow usually starts from people importing large number of issues via CSV, with large number of assets in the list, so we needed it to be automated.

Huge thanks and have a nice day!


author: Franti?ek ?pa?ek _MoroSystems_
body: Hi [@Luka Urushadze](/t5/user/viewprofilepage/user-id/5439595)

it was pleasure to help you. If you can, please accept my answer as an "Accepted answer". thanks to that, this answer will stay on the top and your question will be labeled as answered.

Thanks and have a nice day!


author: Marc - Devoteam
body: Hi [@Luka Urushadze](/t5/user/viewprofilepage/user-id/5439595)

The object that is linked with the asset custom field, what is the cardinality set for the attribute.

By default this is 1, you might need to change that.

comments: author: Luka Urushadze
body: Hi Marc, thanks for the answer! The custom field can hold multiple values when I add them manually, is that still relevant?


author: Marc - Devoteam
body: No, then your cardinality of the custom field of type assets is correct


author: Ryan M
body: Hi Luka,

<br />

I imagine you'd probably have to get creative and use JSON in conjunction with smart values to update this, similar to what's illustrated in solution 2 in this article. <https://support.atlassian.com/automation/kb/how-to-update-a-select-field-multiple-from-the-content-of-other-fields/>  

Have you attempted that yet?

comments: author: Ryan M
body: <https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/> this might contain some more useful information too


author: Luka Urushadze
body: Here's the automation currently:

![Screenshot 2024-08-13 at 21.08.23.png](https://community.atlassian.com/t5/image/serverpage/image-id/341787i49E34C2D6EACA49D/image-size/large?v=v2&px=999 "Screenshot 2024-08-13 at 21.08.23.png")


Tags: assets

automation

cloud

jira-cloud

jsm

premium