Thanks for asking your question on the Exalate Community!
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 receive this on Jira On-Prem system you can use the below code on the incoming Jira-On Prem
issue.customFields.“Jira On Prem Asset Field Name”.value = replica.“Asset Information”
Can you please share the remote replica coming from the cloud side?
It should contain the “Asset Information” in the payload. If this is not available then it would mean we need to further troubleshoot the Jira Cloud outgoing script.
Did you make the necessary changes on the Jira Cloud side (Changing the username and the api token and the object id?)
Please find the attached note pad payload remote replica coming from the cloud side and the asset field name is SAP Perceel & SAP Service. Remote replica from cloud side.txt (9.9 KB)
I am able to see the SAP Perceel & SAP Service in the payload which gives us the workspace id and the object id but I don’t see the Asset Information anywhere in the payload.
Can you please share the complete outgoing script as well.
I don’t see the solution that I provided earlier into your scripts.
Please have a look at my comment from June 23.
I am putting them again for you below.
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()]
]
)def js = new groovy.json.JsonSlurper()
def jsonRes = js.parseText(res)
replica.“Asset information” = jsonRes.label
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 receive this on Jira On-Prem system you can use the below code on the incoming Jira-On Prem
issue.customFields.“Jira On Prem Asset Field Name”.value = replica.“Asset Information”