Forums

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

JSM DC Assets - how to set Asset Objects field in issue with Automation

Trudy Claspill
Community Champion
April 29, 2025

I am working with Jira/JSM DC 9.12.x

We need to set a new Assets Object custom field that has been added to issues. My first thought was to use an Automation Rule. We have ScriptRunner, so we have the Lookup Assets action.

I am successful using Automation to get the Asset I want, and the issue I want to update. I have not yet been able to figure how to actually update the Assets Object field in the issue.

The field is a single-select Assets Object field.

I found a post about doing this for Cloud. I've not found anything explicit for this for Data Center.

https://community.atlassian.com/forums/Jira-questions/Add-assets-to-assets-object-field-through-automation/qaq-p/2557195

I am open to doing scripting instead. I thought it would be simple to do in an Automation rule.

Below are my rule and the log for running the rule. For testing purposes I have limited the scope to one issue that needs updating.

Screenshot 2025-04-29 at 2.22.44 PM.pngScreenshot 2025-04-29 at 2.23.25 PM.png

 

If I manually set the Assets Object field in the issue and then use /rest/api/2/search to output the issue data, it looks like this:


{
"issues": [
{
"key": my-issue-key,
"fields": {
"customfield_12345": [
"Name of object (object-key)"
]
}
}
]
}

 

Why we need to do this:

1. We had a bunch of issues that identified things that we are now converting to Asset Objects.

2. There are a bunch of issues Linked to the issues-that-are-becoming-Asset-Objects.

3. We have added an Assets Object custom field to those other issue types.

4. We want to now update the Assets Object custom field in those other issue types to relate them to the new Asset Objects so that we can, ultimately, archive or delete the original issues-that-are-becoming-Asset-Objects.

5. To facilitate this, when converting the issues to Asset Objects we have a field in the Object for the original issue key.

1 answer

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.
April 29, 2025

Hi @Trudy Claspill 

First the disclaimers: I am not using DC or Assets, and so my suggestions are based on what I know about rules, in general.  With that out of the way...

The JSON expression you are showing uses the asJsonObject() function.  As written, I expect that to produce a result like this:

{
"fields": {
"Site": "{ "key": "SB-1136017" }"
}
}

Which will fail due to the nested double-quotation marks.

What is the type of your field, "Site"?  That earlier article was using the JSON function to help build an array of values, but that would not work for the syntax you show.

 

The other possible thing to check is timing problems with Asset information and the advanced edit with JSON.  I have observed problems where the JSON validation can occur (and fail) before the dynamic expression can fully parse.  (The same thing happens with the Send Web Request action for URLs and the request body.)

I recommend pre-building the JSON into a created variable first, and then using that variable in the advanced edit.  This will ensure it fully evaluates before use.  (It can also be logged to check the validity of the JSON in an external tool by copy-and-pasting the log text there.)

 

Kind regards,
Bill

Trudy Claspill
Community Champion
April 29, 2025

Thank you for the suggestions @Bill Sheboy .

The Site field is an Assets Object custom field.

What I was hoping to get as an answer was an actual example of how somebody successfully set an Assets Object (single selection) field through Automation on Jira DC, with bonus points if they did it after getting the object from a Lookup Assets action. The Adaptavist documentation doesn't have an example of this, and I haven't been able to find any examples specific to DC.

But I'll see if I can make more progress with the suggestions you've provided. Thanks, again!

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.
April 30, 2025

No worries, and based on the hard-coded example you tried, perhaps try this:

  • action: create variable
    • name: varJson
    • value:
{
"fields": {
"Site": {{lookupAssets.objectKey.asJsonObjectArray("key")}}
}
}
  • action: log the value of {{varJson}}
  • action: edit issue, with the variable as the JSON, {{varJson}}

 

That function will add the array syntax and handle multiple values when they are present.

And if that does not work, try the "update" with an "add" operation rather than "fields" for a replacement.

Like Trudy Claspill likes this
Trudy Claspill
Community Champion
April 30, 2025

I haven't had a chance to work on this, but my colleagues gave me the following tips also.

it looks like you're trying to set the asset field using the ID of the object you looked up, so you'll want to make sure that the Asset custom field is configured to locate the object using the object key ID. A lot of times this field is set to locate based on the primary label or title of the object, you can configure the field to locate based on multiple attributes.

The above is true; I don't have the field including the Key of the object. So I think that will be the first thing I test - updating the configuration of the field.

 

A reference with Automation rules, way at the bottom of the page:

https://confluence.atlassian.com/automation0902/advanced-field-editing-using-json-1431247626.html

 

 

Trudy Claspill
Community Champion
April 30, 2025

This was the final solution:

 

I did not need to add Key to the Assets Custom field configuration.
The smart value to get the object key did not need to be so complex.

Changing the Advanced Editing to this worked:

{
"fields": {
"customfield_XXXXX": [{"key" : "{{lookupAssets.objectKey}}"}]
}
}

 

Like Bill Sheboy likes this

Suggest an answer

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

Atlassian Community Events