Forums

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

How to use lookupAssets to return the accountId, email or name from a User field in Assets

Holly Schu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 26, 2024

I am using an assets lookup  to a User field in order to return a user from Assets: 

{{#lookupAssets}}{{#first}}{{attributes."Assigned To"}}{{/}}{{/}}

This is returning:   JIRAUSER74326

I then try to access this from a script runner script and I get:

com.adaptavist.hapi.platform.exceptions.InvalidUserNameException:
No user exists with the username 'JIRAUSER74326'

I have tried 

 

{{#lookupAssets}}{{#first}}{{attributes."Assigned To".name}}{{/}}{{/}}

{{#lookupAssets}}{{#first}}{{attributes."Assigned To".accountId}}{{/}}{{/}}

these both return blank.

My ultimate goal is to set a custom user field in an issue from a user field in assets. 

Thank you.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
June 28, 2024

Hi @Holly Schu

Instead of using the Asset Lookup, I suggest using the Execute a ScriptRunner script option so you will have more control.

Below is a sample working code for your reference:-

import com.adaptavist.hapi.jira.assets.Assets
import com.adaptavist.hapi.jira.users.Users

Assets.search("objectType = Staff").each { asset ->
def username = asset.getString('Username') as String

if (Users.getByName(username)) {
log.warn "========>>> ${Users.getByName(username).name}"
}
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.

Below is a screenshot of the Automation configuration:-

automation_config.png

With the approach above, I am searching for all the Users in the Assets called Staff.

From the result obtained in the IQL Query, I am checking their Usernames against the Users class to see if they exist. 

If they exist, they will be printed out in the log.

You will need to modify it according to your requirements.

Thank you and Kind regards,
Ram

Holly Schu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 2, 2024

Thank you.  I will try it and get back to you.

0 votes
Karolina Dylewicz
February 6, 2026

I think you don't need ""

{{#lookupAssets}}{{#first}}{{attributes."Assigned To".name}}{{/}}{{/}} 

but probably it's even more than that.

For me a simpler version with a different attribute worked: 

{{#lookupAssets}}{{#first}}{{attributes.Name}}{{/}}{{/}}

 

Evie Z_
Community Manager
Community Managers are Atlassian Team members who specifically run and moderate Atlassian communities. Feel free to say hello!
February 6, 2026

This topic is now closed as the discussion has become outdated. If you have more questions or want to continue the conversation, feel free to start a new topic. For more details on why we close older threads, check out our Rules of engagement - Atlassian Community .

Thank you for your understanding!