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.
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:-
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
Thank you. I will try it and get back to you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.