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.

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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.

Suggest an answer

Log in or Sign up to answer