Forums

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

Updating assets attributes with multiple values

Lara Lopez
Contributor
October 17, 2024

Hello,

I am trying to update an assets object with the information of Jira customfields with scriptrunner HAPI. Some of the attributes can hold multiple values. I I have the code that works for example for objects but I do not seem to make it work for objects with attributes of the type "Jira Project" or "Emails".

I know that I can use this for text fields:

if (teamname) setAttribute('Name', teamname)

 

Or this for objects

 if (objectKey != null) {
            architectlist.each { tm ->
            def asset = Assets.getByKey(objectKey)
            asset.update {
                setAttribute('Architect') {
                    add(tm)
                }
             }
         }
}
But when I try to use the second one to add multiple emails or Jira projects to an attribute field it fails. Does anyone know what should be the correct way? Can it even be done by HAPI or do I have to use regular code?

1 answer

0 votes
Sergei Troshin
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 20, 2024

Hi @Lara Lopez 

Try out this:

def x = Assets.getByKey("TEST-1")

x.update {
    setAttribute("Project", 10100, 10300, 10000)
}
P.S. Paste yours Project Ids instead of my 10100, 10300, 10000

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events