access Asset object attributes in postfunction

Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 15, 2023

Hi 

I want to access attribute values in an Assets object i.e. address details for an email or store in a text field.

I am using JMWE at the moment but could also try Scriptrunner if there is a solution there.

I can see my object using

{{ issue | insightFieldValue("customfield_10076") | first | field("label") }}

But I want to get at the attributes. The structure I can see via a dump() is

{
"id": "ed27ff36-cae3-4680-979c-a7457da17e:3496",
"objectKey": "ITEM-3496",
"label": "Site 1",
"objectType": {
"id": "ed27ff36-cae3-4680-979c-a7757da17e:16",
"name": "Site"
},
"attributes": {
"country": {
"value": "England",
"displayValue": "England",
"searchValue": "England"
}
}
}

Any one else solved this?

2 answers

1 accepted

1 vote
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 15, 2023

Hi @Tom Lister 

since this seems to be a single-value Insight field, you don't need to use the "first" filter (which is needed when the value is an array).

So to access the label of the Insight object, you can do:

{{ issue | insightFieldValue("customfield_10076") | field("label") }}

And for, say, the country name:

{{ issue | insightFieldValue("customfield_10076") | field("attributes.country.value") }}
Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 15, 2023

Brilliant - just the job

{{ issue | insightFieldValue("customfield_10076") | first | field("attributes.country.value") }}
Swapnil Srivastav March 15, 2024

Hello @David Fischer ,

Thank you very much for sharing. I want to traverse through the values of a multi-value asset object field and compare the values with string values. Is it achievable with JMWE?

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 15, 2024

Hi @Swapnil Srivastav ,

yes, this is doable, you'll need to write some Nunjucks code, using the for statement:

{% for item in issue | insightFieldValue("customfield_10076") %}
{% if item.attributes.country.value == "some string" %}
SOME VALUE
{% endif %}
{% endfor %}
0 votes
Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 15, 2023

Progressing slightly.

I can see the attributes only using

{{ issue | insightFieldValue("customfield_10076") | first | field("attributes") | dump() }}

The question now is how filter the value for "country"

I can find it by "value"

{{ issue | insightFieldValue("customfield_10076") | first | field("attributes") | filter({value:"England"}) | first | dump() }}
 
{"value":"England","displayValue":"England","searchValue":"England"}

but i want to find specific values by attribute name

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events