Match users in CSV import to user type attribute of Assets objects
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
To importing users as attribute values in Assets cloud, you must provide their Atlassian Account ID. The import tool in Assets does not automatically match user accounts in your site when you provide their emails in a CSV file.
There is an open feature request to implement this: JSDCLOUD-10487 - Allow to use user email address when import user attribute in Assets.
This article provides a solution to find the account IDs, and also to use an automation rule to update the user type attribute for an object assuming you have the user's email address stored in another attribute of the same object.
Solution
Find the Atlassian Account ID for users
To obtain a the Atlassian Account IDs in your site, you can export all users into a CSV file. This can be done by navigating to yoursitename.atlassian.com/admin/users > Export users. Once you have the account IDs, update the objects with the corresponding Jira users in your file.
Use automation to update user attribute based on email addresses
Let's say you have an object type called "Person" that has the attributes:
"Jira User" of type "User" - this attribute needs to be updated with the corresponding Jira user for that object
"Manager" of type "Object" - this attribute is self-referenced and stores the manager object of the user
"Jira Manager" of type "User" - this attribute needs to be updated with the corresponding Jira user of the manager for that object
"mail" of type Text - stores the email address of the user
These steps will help you to update the "Jira User" attribute with the corresponding user by fetching the user details using the email address stored in the "mail" attribute:
Create a global automation rule that triggers when an object is created. (You can also use the scheduled trigger followed by a Branch on AQL)
Create a Branch on AQL. Choose the desired schema and specify the AQL:
Add twoCreate variable actions and create these variables:
Variable 1:
name: EMAIL
Smart value:
{{object.email}}
Variable 2:
Name: emailManager
Smart value:
{{object.Manager.mail}}
Add a Send web request action to get the User account ID using the search user API:
Web request URL:
https://<Cloud site URL>/rest/api/3/user/search?query={{EMAIL.urlEncode}}
Configure three Headers:
Content-Type: application/json
Accept: application/json
Authorization: In the Authorization header make sure that you add the keyword Basic followed by the base64 of your emailaddress:APItoken. So if the base64 of the emailaddress:APItoken is AB12XY45 then to the Authorization header add the value Basic AB12XY45.
HTTP method: GET
Web request body: Empty
Check the option "Delay execution of subsequent rule actions until we've received a response for this web request" as the response contains the Atlassian account ID of the user.
Create variable in the rule to store account id of the user:
Variable name: AAIDUser
Smart value:
{{webResponse.body.accountID}}
Next, send a web request using Send web request action again. Use the same content from step 4 except for the Web request URL field which should be:
https://<Cloud site URL>/rest/api/3/user/search?query={{emailManager.urlEncode}}
⚠️ Make sure you check the option "Delay execution of subsequent rule actions until we've received a response for this web request"
Add another Create variable to store account id of the manager:
Variable name: AAIDManager
Smart value:
{{webResponse.body.accountID}}
Add an action to Edit object and set the attributes using the variables you just created:
Jira Manager:
{{AAIDManager}}
Jira user:
{{AAIDUser}}
Publish the rule.
You can edit the rule as per your requirement, for example in case you do not have the manager attribute, by removing those actions.
Update more than 50 objects
Automation has a limit where it can only update 50 objects at once. So depending on the number of users you would like to update, it can happen that no new objects are picked by the branch as "Jira user" remains empty for these objects.
In that case, you can add an attribute in "Person" object type, say "Last Sync date" of type date and use this to go through the objects which have not been synced since the last update. This value will help us to iterate over all the objects using automation rule and update will be performed only on those objects which have not been updated on that day.
After you have added the above attribute, you need to make changes to the above rule as below:
Update the AQL in branch as:
objecttype = "Person" and mail is not empty and "Jira User" is empty AND ("Last Sync date" < startOfDay() OR "Last Sync date" IS EMPTY)
This will only check those objects which have not been picked up by the automation rule on the same day.
In the Edit object action, add attribute "Last Sync date" and provide the value:
{{now.format("dd/MMM/yy")}}
This will update the attribute to store the date when the automation rule picked this object to check for the corresponding Jira user.
Another option is to make use of Dynamic Looping.
We have a feature request to expand the number of objects that can be updated per rule: JSDCLOUD-10643 - Ability to update more than 50 objects in a single Assets automation run.
For more examples refer to the article Update Asset object attribute values using automation
Was this helpful?