Update asset schema data from Jira issue.

Crystal Rouse
Contributor
April 3, 2024

I am trying to update our asset schema from a Jira issue.  Other than groovy script, are there any other ways to accomplish this?

If I have to use groovy script, are there any help guides or instructions?

Thanks!

2 answers

2 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
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.
April 26, 2024

There are some built-in asset modification post functions. But they are fairly limited.

Scriptrunner will give you much more flexibility.

The HAPI scriptrunner framework makes these tasks a lot simpler than they used to be.

You can study this page: https://docs.adaptavist.com/sr4js/latest/hapi/work-with-assets-insight

But if you have some specifics, I can help you build a simple script to take a value from a custom field and update an attribute on a linked asset (as specified by another custom field. Here is a generic sample:

 

import com.riadalabs.jira.plugins.insight.services.model.ObjectBean

def assetCfName = 'Asset Custom Field Name'
def valueCfName = 'New Attribute Value Field Name'
def attributeToUpdate = 'Attribute Name To Update'

def assetObjectToUpdate = issue.getCustomFieldValue(assetCfName)

//asset cf can contain lists of object, let's assume you've restricted yours to single values (byt the API doesn't know that)
if(assetObjectToUpdate instanceof List){
//we found a list of objects (even if the list is size 1) let's take the first in the list
assetObjectToUpdate = assetObjectToUpdate[0]
}
def valueToSet = issue.getCustomFieldValue(valueCfName) as String

//"as objectbean" is not necessary, but it helps hide static type checking errors
(assetObjectToUpdate as ObjectBean).update{
setAttribute(attributeToUpdate, valueToSet)
}
Crystal Rouse
Contributor
May 3, 2024

Thanks so much!

0 votes
Answer accepted
Dirk Ronsmans
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 3, 2024

Hi @Crystal Rouse ,

Let me first ask your if you are on Cloud or Datacenter? The options could be different based on that :)

Crystal Rouse
Contributor
April 5, 2024

DataCenter

Thanks!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events