I have a situation where I have multiple organized object types with objects in them. I need those objects to automatically be copied into a single "Gold Dataset" object type every so often, so they can be searched through and selected through cascading drop-down menus.
All of the attributes are named the same, and the object types are in the same object schema. At first I thought this wouldn't be complicated to do, but it looks like Atlassian doesn't have the built-in capability to do this. Unless I'm wrong and there is some hidden functionality I could be using?
So, I'm somewhat stumped on how to accomplish this. I believe I may have to use automation and Groovy scripts to be able to copy the objects over, but I'm unfamiliar with the language and I don't know how JSM interfaces with it.
If someone knows something I don't, any assistance would be appreciated.
I created a groovy script to be run through ScriptRunner as a scheduled job every 30 minutes. It doesn't format very well even in a code block, but it functions for what I'm using it for.
import org.apache.log4j.Logger
/*
This script copies objects from the object type IDs:
(597,598,599,600,382) into ID (618) object type (GOLD)
*/
// Assets.count('objectSchemaId = 5 and objectTypeId IN (597,598,599,600,382) order by Updated desc') // count of total items in object types
// Search through source object types for objects created within the past minute
Assets.search('objectSchemaId = 5 and objectTypeId IN (597,598,599,600,382) AND "Updated" <= now() AND "Updated" > now(-31m)').each { sourceObject ->
// Define successCount variable for checking if object exists
def successCount = 0
// Search through target object type
Assets.search('objectSchemaId = 5 and objectTypeId = 618').each { targetObject ->
// Compare sourceObject and targetObject
if(sourceObject.getName() == targetObject.getName()) {
// Add success for correct match
successCount += 1
// Fetch source variables
def attr1, attr2, attr3, attr4, attr5, attr6, attr7, attr8, attr9, attr10, attr11, attr12, attr13
try { attr1 = sourceObject.getString("Barcode")
} catch(Exception e) { log.warn "Barcode does not exist"
attr1 = null }
try { attr2 = sourceObject.getName()
} catch(Exception e) { log.warn "Name does not exist"
attr2 = null }
try { attr3 = sourceObject.getReference("Manufacturer").getString("Name")
} catch(Exception e) { log.warn "Manufacturer does not exist"
attr3 = null }
try { attr4 = sourceObject.getReference("Model").getString("Name")
} catch(Exception e) { log.warn "Model does not exist"
attr4 = null }
try { attr5 = sourceObject.getString("Serial Number")
} catch(Exception e) { log.warn "Serial Number does not exist"
attr5 = null }
try { attr6 = sourceObject.getReference("Building").getString("Name")
} catch(Exception e) { log.warn "Building does not exist"
attr6 = null }
try { attr7 = sourceObject.getReference("Room").getString("Name")
} catch(Exception e) { log.warn "Room does not exist"
attr7 = null }
try { attr8 = sourceObject.getReference("Rack").getString("Name")
} catch(Exception e) { log.warn "Rack does not exist"
attr8 = null }
try { attr9 = sourceObject.getString("Elevation")
} catch(Exception e) { log.warn "Elevation does not exist"
attr9 = null }
try { attr10 = sourceObject.getReference("System Owner").getString("Name")
} catch(Exception e) { log.warn "System Owner does not exist"
attr10 = null }
try { attr11 = sourceObject.getReference("Guild").getString("Name")
} catch(Exception e) { log.warn "Guild does not exist"
attr11 = null }
try { attr12 = sourceObject.getDate("EOL")
} catch(Exception e) { log.warn "EOL does not exist"
attr12 = null }
try { attr13 = sourceObject.getDate("EOS")
} catch(Exception e) { log.warn "EOS does not exist"
attr13 = null }
// Update target object based on source
targetObject.update {
if(attr1 != null) { setAttribute("Barcode", attr1) }
if(attr2 != null) { setAttribute("Name", attr2) }
if(attr3 != null) { setAttribute("Manufacturer", attr3) }
if(attr4 != null) { setAttribute("Model", attr4) }
if(attr5 != null) { setAttribute("Serial Number", attr5) }
if(attr6 != null) { setAttribute("Building", attr6) }
if(attr7 != null) { setAttribute("Room", attr7) }
if(attr8 != null) { setAttribute("Rack", attr8) }
if(attr9 != null) { setAttribute("Elevation", attr9) }
if(attr10 != null) { setAttribute("System Owner", attr10) }
if(attr11 != null) { setAttribute("Guild", attr11) }
if(attr12 != null) { setAttribute("EOL", attr12) }
if(attr13 != null) { setAttribute("EOS", attr13) }
}
}
}
// Create object if it doesn't exist in target object type
if(successCount != 1) {
Assets.create("ASSETS", "GOLD") {
// Define attributes using source data
def attr1, attr2, attr3, attr4, attr5, attr6, attr7, attr8, attr9, attr10, attr11, attr12, attr13
try { attr1 = sourceObject.getString("Barcode")
} catch(Exception e) { log.warn "Barcode does not exist"
attr1 = null }
try { attr2 = sourceObject.getName()
} catch(Exception e) { log.warn "Name does not exist"
attr2 = null }
try { attr3 = sourceObject.getReference("Manufacturer").getString("Name")
} catch(Exception e) { log.warn "Manufacturer does not exist"
attr3 = null }
try { attr4 = sourceObject.getReference("Model").getString("Name")
} catch(Exception e) { log.warn "Model does not exist"
attr4 = null }
try { attr5 = sourceObject.getString("Serial Number")
} catch(Exception e) { log.warn "Serial Number does not exist"
attr5 = null }
try { attr6 = sourceObject.getReference("Building").getString("Name")
} catch(Exception e) { log.warn "Building does not exist"
attr6 = null }
try { attr7 = sourceObject.getReference("Room").getString("Name")
} catch(Exception e) { log.warn "Room does not exist"
attr7 = null }
try { attr8 = sourceObject.getReference("Rack").getString("Name")
} catch(Exception e) { log.warn "Rack does not exist"
attr8 = null }
try { attr9 = sourceObject.getString("Elevation")
} catch(Exception e) { log.warn "Elevation does not exist"
attr9 = null }
try { attr10 = sourceObject.getReference("System Owner").getString("Name")
} catch(Exception e) { log.warn "System Owner does not exist"
attr10 = null }
try { attr11 = sourceObject.getReference("Guild").getString("Name")
} catch(Exception e) { log.warn "Guild does not exist"
attr11 = null }
try { attr12 = sourceObject.getDate("EOL")
} catch(Exception e) { log.warn "EOL does not exist"
attr12 = null }
try { attr13 = sourceObject.getDate("EOS")
} catch(Exception e) { log.warn "EOS does not exist"
attr13 = null }
// Assign data to new object
try {
if(attr1 != null) { setAttribute("Barcode", attr1) }
if(attr2 != null) { setAttribute("Name", attr2) }
if(attr3 != null) { setAttribute("Manufacturer", attr3) }
if(attr4 != null) { setAttribute("Model", attr4) }
if(attr5 != null) { setAttribute("Serial Number", attr5) }
if(attr6 != null) { setAttribute("Building", attr6) }
if(attr7 != null) { setAttribute("Room", attr7) }
if(attr8 != null) { setAttribute("Rack", attr8) }
if(attr9 != null) { setAttribute("Elevation", attr9) }
if(attr10 != null) { setAttribute("System Owner", attr10) }
if(attr11 != null) { setAttribute("Guild", attr11) }
if(attr12 != null) { setAttribute("EOL", attr12) }
if(attr13 != null) { setAttribute("EOS", attr13) }
} catch(Exception e) { log.warn sourceObject
log.warn e.getMessage() }
}
}
}
I have a similar task of automating imports from Jamf Cloud to Jira Assets. My script is able to download the json file from Jamf but I don't know what to do next to automate it. Jamf documentation doesn't get that specific and Jira documentation is very fragmented : (
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dom L
To do that you need two things :
The reason you need to have your files on a public web server is that you don't have to manually change the file in your Import configuration. If you don't want to do that (which I would understand) you would need to manually import them from time to time.
Without creating complex PowerShell scripts, I don't know of another way to do so.
Hope this helps.
Have a nice day
Frederic Chartrand - FMX Solutions - Gold Solution Partner
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the response.
I do know how to use automation to import assets regularly, but I'm having trouble with the exporting side of it, and with the scripting of the whole process. Is there a way to do that with groovy scripting at all? Or maybe a Jenkins job?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dom L
That's a good question. I looked at the Rest API doc and can't find anything to export data. I don't know enough about Groovy or Jenkins to elaborate unfortunately.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.