12-15-2023 02:50 PM
Hello,
I am having a very tough time figuring out how to work with objects I get from Atlassian's API. Because their objects have so many custom fields, they don't use simple key-value pairs.
As an example, the object within the Values array here represents a specific laptop asset. Within the Attributes array in that object, the laptop's attributes are listed. However I cannot identify attributes programmatically using the attribute names... or even IDs... because of the formatting.
In order to get the "UDID" attribute value for this laptop, I need to find the object within the Attributes array where "Object type attribute ID" = 325. When I find that object, I need to look to the "Object attribute values" array within the object... look at the first object within that array, and use the value associated with the "Value" key.
How on earth can I make this work with Workato? Atlassian has made this SO complicated.
Solved! Go to Solution.
12-15-2023 04:00 PM
Hallelujah!!! Made a few changes to process the larger object containing both arrays... first define the ugly object using IDs but simplifying the ID-Name relationship. Then go back through that object and replace the IDs with names using the 2nd array.
Thank you @gary1 for the code that got me started!!
## provide the findIdentifiers array as your "data" input and grab it
inputObject = input["data"]
attributesArray = inputObject["values"][0]["attributes"]
definitionsArray = inputObject["objectTypeAttributes"]
new_object= {}
## loop through findIdentifiers
attributesArray.each { | a |
new_object[a["objectTypeAttributeId"]] = a["objectAttributeValues"][0]["displayValue"]
}
## loop through findIdentifiers
definitionsArray.each { | a |
## dig up the type value; this assumes only one object in the Type array
typeId = a["id"]
if new_object.has_key?(typeId)
# Rename "old_key" to "new_key"
new_key = a["name"]
old_key_value = new_object.delete(typeId)
new_object[new_key] = old_key_value
end
}
## create the output object with itemsToKeep as the value
{result: new_object}
12-16-2023 02:45 AM
Hey @runelynx , could you share the raw JSON response using the "Copy Raw JSON" button?
If the response has a fixed schema, it shouldn’t be difficult to retrieve the specific field you need without using Ruby code.
12-16-2023 03:49 AM
Hi @runelynx,
I started a few days ago with a new Jira Assets connector, as I also couldn't believe how people show handle that super-complicated data format Jira Assets is using. I tried to abstract from the underlying technical stuff and make it simple to use the connector.
Created a short video to show/illustrate how it works: https://youtu.be/0R5aRcAuqdA
Import to note: In order to handle the Object-Type-Schema properly, you have to configure the Object-Type as part of the action. Depending on the number of object types you have it would required a number of If-Statements, but there is no other around it, as the Schema needs to be know and Config-Time.
Would that be okay for your use-case?
Please let me know your feedback. I'm also happy to share this connector with you once I'm happy with it.
Cheers,
Chris
01-03-2024 11:18 PM
Happy new year!
The new Jira Assets connector is now avilable in the community library:
https://app.workato.com/custom_adapters/513076/details?community=true
Please let me know, if this works for your use-case(s) or if you miss anything.
Cheers,
Chris