How to append list of objects to a reference Assets object attribute using Automation

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

Customers can create an Assets Object and set its attributes via automation. However currently, we cannot append an Assets object attribute of reference type via automation.

This kb covers the scenario when you need to append an Assets object attribute of reference type via automation. If you are looking to just copy/add the new values in a reference Assets object attribute via automation refer to the kb: Copy/add list of objects to a reference Assets object attribute using Automation

The method in this article requires less technical knowledge to utilize: How to Append Objects to an Assets Object Attribute using Automation 

For more examples refer to the article Update Asset object attribute values using automation

Environment

 Automation for Jira and JSM Assets

Cause

We have this behavior described on the feature request JSDCLOUD-9964 - Getting issue details... STATUS to see the possibility of providing the functionality to be able to copy a list of objects to a reference Assets object attribute that is created via automation.

Solution

Access request to new applications (Append new values to a referenced Assets object attribute)

Let's say you have an Assets object field "Application List" that stores the list of Applications the new employee needs access to. "Application List" Assets object field is fetching the objects from an object type called Applications. Also, you have an Employee object type that has an attribute "Application access" which references to object type Applications with unlimited cardinality. 

Whenever an Employee requests access to a new set of applications mentioned in the "Application List" Assets object field, once the access is provided by the agent, the list of new applications should be updated in the "Application access" attribute for the Employee object. Here is an employee who currently has access to 3 applications App1, App2, App3. The employee raises a new Access request to get access to the applications App4, App5. The Employee Assets object field is set to the Employee "FirstName LastName" with the "Application access" attribute set as App1, App2, App3. And Application List Assets object field is set to application objects App4, App5. 

Here are the steps to append the list of applications in use by the Employee object:

  1. Create an automation rule that triggers when the agent has provided the access to new applications and the access request is closed 
  2. Note that at the moment, it is not possible to update the attribute values using REST API as Rest API is performing a strict update that just overwrites the value and doesn't append multiple values. So here is what we do to append the values:
    1. Use the below smart value to get the new list of applications mentioned in the Application List Assets object field, and need to be updated in the object Employee

      {{"Application List".Key.asJsonObject("value")}}
    2. We cant use the same format to get the current list of applications mentioned in the Employee object because they are actually stored in the objects reference type attribute. So this doesn't work:

      {{Employee."Application access".Key.asJsonObject("value")}} (DOESN'T WORK)

      We are going to use the below smart value to get the current list of applications along within a Branch AQL action:  

      {{object."Application access".Key.asJsonObject("value")}} 
  3. Add an AQL branch to find the Employee object to be edited so that we can fetch the current list of applications for the Employee (To Add Branch AQL make sure the automation rule context is global and not limited to a project)

    objecttype = Employee and Name = "{{Employee.Name}}"

  4. Add a log action within the branch to make sure we get the desired results:

    List of application: {{object."Application access".Key.asJsonObject("value")}},{{"Application List".Key.asJsonObject("value")}} object to be edited: {{object.id}}
  5. In the Branch add a Send web request action to send the Update object REST API o the object to be edited:
    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

      1. Note: The API Token referenced here is generated under an Atlassian Account's Profile Page. It is not the Import Configuration Token generated for Assets Imports.
      2. Note: When using Powershell to encode the string to base64, the source encode matters. In this case, UTF8 should be used. This is mentioned in our Basic Auth for REST APIs page.
    2. Add the following Web request URL:

      https://api.atlassian.com/jsm/assets/workspace/<YOUR WORKSPACE ID>/v1/object/{{object.id}}

      If you are not aware of the workspace id: Find your workspace ID

    3. Add the following to the Custom data field:

      {
          "attributes": [
              {            "objectTypeAttributeId": "2355",
                  "objectAttributeValues": [{{object."Application access".Key.asJsonObject("value")}},{{"Application List".Key.asJsonObject("value")}}]
              }
          ]
      }

  6. Here is how the rule execution looks like:
    Before execution:


    Execution Audit log:


    After execution:


Please reach out to support if you have any questions. 

Last modified on Jan 8, 2024

Was this helpful?

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