Forums

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

Scriptrunner - update Assets field with an array of vlaues

Chris Shepherd
Contributor
August 23, 2023

Hi folks,

Within assets we have servers lumped into groups.  We would like to be able to put a group name into a field and have it fill with all the servers in that group.

I current have this working using the following code:

def issue = Issues.getByKey('JTA-1')
def targets = issue.getCustomFieldValue("Change Targets")
def servers = []

targets.each { object ->
  if (object.objectTypeId == 3158){
    def iql = '"Patch Phase" = ' + object.getObjectKey()
    Assets.search(iql).each { server ->
      servers.add(server)
     }
  }
}

log.debug("Adding ${servers.size} servers to change target")

servers.each { server ->
    log.debug("Adding ${server}")
    issue.update {
      setCustomFieldValue("Change Targets") {add (server)}
    }
}

Unfortunately this is really slow as it does an update for each item,  I figure there must be a way to set the custom field value to an array in one go,  but i cannot figure it out.

Any ideas ?

1 answer

1 vote
Hauke Bruno Wollentin
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.
August 23, 2023

Maybe I don't get it right, but for the desired behaviour you do not need to do Groovy magic at all.

You could have a "Group" Assets custom field which is selectable by the user and you could have your "Change targets" which also could be an Assets custom field. In the latter you can simply use the "Filter Assign Scope (AQL)" and refer to the "Group" custom field together with the "Assign strict" option.

Chris Shepherd
Contributor
August 23, 2023

We need the Jira linked to each individual server, not the group.

Hauke Bruno Wollentin
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.
August 30, 2023

Yes, that's the case if you use the "Filter Assign Scope" in the "Change targets" fields based on the "Group" field.

This will automatically put all server objects that belongs to the chosen group into that custom field.

But maybe I'm misunderstand what you mean with "linking the ticket to each server"

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events