Hi Kevin,
This is my outgoing script String key = issue.key
def result = httpClient.get(“/rest/api/latest/issue/”+“$key”)
def workspaceId = (“${result.fields.“customfield_11034”.workspaceId}”).replace(“[”, “”).replace(“]”, “”)
def objectId = (“${result.fields.“customfield_11034”.objectId}”).replace(“[”, “”).replace(“]”, “”)
def USER = “my email id”
def TOKEN = “Api 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
and in incoming script we are using this
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
final String DESTINATION_ASSET_FIELD_ID = “customfield_14301”
def USER = “email id”
def TOKEN = “API token”
def DESTINATION_WORKSPACE_ID = “destination workspace id”
def OBJECT_TYPE_ID = “destination onject type id”
// The label synced from the source issue
def assetLabel = replica.“Asset information”
if (assetLabel) {
def aqlQuery = "objectType = ${OBJECT_TYPE_ID} AND Label = \"${assetLabel}\""
def searchUrl = "https://api.atlassian.com/jsm/assets/workspace/${DESTINATION_WORKSPACE_ID}/v1/object/search"
def authHeader = "Basic ${(USER + ":" + TOKEN).bytes.encodeBase64().toString()}"
def requestBody = JsonOutput.toJson([aql: aqlQuery])
def res = new GroovyHttpClient(nodeHelper).http(
"PUT",
searchUrl,
requestBody,
[
"Content-type": ["application/json"],
"Authorization": [authHeader]
]
)
def js = new JsonSlurper()
def searchResult = js.parseText(res.body)
if (searchResult && searchResult.size() > 0) {
// We found at least one matching object. Use the first one.
def foundObjectId = searchResult[0].id
// 4. Update the destination issue field (issue)
def updateValue = [[
"workspaceId": DESTINATION_WORKSPACE_ID,
"objectId": foundObjectId
]]
// Update the field on the destination issue
issue.fields."${DESTINATION_ASSET_FIELD_ID}" = updateValue
}
}
Just and FYI we are syncing between two instances where the object ids are different in both the instances, we have tried from postman, we are able to update the value if the object id is hardcoded {
"fields": {
"customfield_14301": [
{
"workspaceId": "workspace id",
"id": "workspaceid:401982",
"objectId": "401982"
}
]
}
}