Synchronization from Asset type field to Text field

We have a requirement like to Synchronize two fields from cloud to onpremise jira.

On cloud we have two fields like SAP Perceel & SAP Service both are Assets objects field type. It should be mapped to onpremise jira as a text fields.

I have tried based on the below document, but I didn’t get any solution.

How to Sync Insight Custom Fields

Kindly help me on the requriement.

Hi @VS57 ,

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()]
    ]
    )

    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”

Thanks, Dhiren

GroovyHttpClient.groovy (7.6 KB)