How to update user type attribute of an Asset objects using Automation after Import

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

While importing the user type attribute in Assets, it is necessary to provide the Atlassian Account ID of the user. We have a feature open to allow user attributes to be imported using their email address JSDCLOUD-10487 - Getting issue details... STATUS

However, it is not always necessary that the CSV file always contains this information and you only have their name and email address. You would have to manually fetch their Atlassian Account IDs by exporting all the users of your site in a CSV file by going to User Management > Export users and then, update the objects with the respective Jira users.

This KB article allows you to update the user type attribute for an object created, provided you have their email address stored in another attribute of the same object. 

Environment

Automation for Jira and JSM Assets

Solution

Let's say you have an object type called "Person" that has the below 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

The below 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.

  1. Create a global automation rule that triggers when an object is created. ( (info) You can also use the scheduled trigger followed by a Branch on AQL) 
  2. Create a new branch > Branch on AQL. Choose the desired schema and specify the AQL:

    objecttype = "Person" and mail is not empty and "Jira User" is empty

     

  3. Click on New action > Create variable  and create 2 variables as below:
  4. Add a Send web request action to get the User account ID using the search user API:
    1. 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

    2. Add the following Web request URL:

      https://<Cloud site URL>/rest/api/3/user/search?query={{EMAIL.urlEncode}}
    3. Add the Content-Type  and "Accept" header
    4. 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.

  5. Create variable to store account id of the user by clicking on New action > Create variable as below:
  6. Next, send a web request using Send web request action again. But this time, change the URL as below to get the Jira user details of the manager:

    https://<Cloud site URL>/rest/api/3/user/search?query={{emailManager.urlEncode}}

    (warning)  Make sure you check the option "Delay execution of subsequent rule actions until we've received a response for this web request"

  7. Create variable to store account id of the manager by clicking on New action > Create variable as below:

  8. Click on New action > Edit object and choose the below attributes and set values as below:
  9. Publish the rule by giving it a name.

You can edit the rule as per your requirement in case you do not have the manager attribute by removing those actions. 

Note

In cases where you have more than 50 objects to update the user-type attribute, it can happen that some of your objects do not have a corresponding Jira user on your site. Due to the limit of branch that can take atmost 50 objects, it can happen that no new objects are picked by the branch as "Jira user" remains empty for these objects. 

In that case, to achieve this and iterate over all the objects, 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:

  1. 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.

  2. 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.


Please reach out to support if you have any questions. For more examples refer to the article Update Asset object attribute values using automation 


Last modified on Dec 26, 2023

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.