We are syncing issues between two projects on the same Jira Cloud instance. While most fields (standard and custom) are syncing as expected, we are encountering issues with syncing Assets (Insight) custom field values. These fields are populated on the source issue but are either not being transferred or appear as empty/null on the destination issue.
Since Exalate does not directly support the sync of Asset Fields directly, we will leverage the Groovy scripting interface offered by Exalate and use HttpClient to make an API call to the Asset Endpoint provided by Atlassian to get the value of the Asset field based on the custom field id that we provide.
Here’s the solution.
Include the GroovyHttpClient class into the outgoing script on the sending side where the Assets field is being exported from: GroovyHttpClient.groovy
Now in your outgoing script, please include the following API call:
//getting the workspaceid and objectid from Jira Issue API
String key = issue.key
def result = httpClient.get(“/rest/api/latest/issue/”+“$key”)
def workspaceId = (“${result.fields.“customfield_10062”.workspaceId}”.replace(“[”,“”).replace(“]”,“”))
def objectId = (“${result.fields.“customfield_10062”.objectId}”.replace(“[”,“”).replace(“]”,“”))
def USER = “<<jira_username>>”
def token = “<<jira_token>>”
//def token = System.getenv(“token”)
//getting the Asset field details using the above fetched workspace and objectid using groovy http client
def res = new GroovyHttpClient(nodeHelper)
.http(
“GET”,
“https://api.atlassian.com/jsm/assets/workspace/${workspaceId}/v1/object/${objectId}”,
null,
[
“Content-type” : [“application/json”],
“Authorization” : [“Basic ${(USER+”:“+token).bytes.encodeBase64().toString()}”.toString()]
]
)
The only changes required will be on
lines 4 and 5: use the correct custom field ID
lines 6 and 7: enter your username and API key (we can hide the key away from the scripts later)
Once we send this information to the other side, we can use a similar logic to find the id of the object and set this via REST API.