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)

Hello Dhiren,

Thanks for the information which you have provided.

I have implemented same script in outgoing script but in the Incoming script for jira on prem the I’m getting error on the script.

incoming Jira-On Prem:

issue.customFields.“24934”.value = replica.“Asset Information”

This 24934 is a text field.

Hi @VS57 ,

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?)

Thanks, Dhiren

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)

Hi @VS57 ,

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.

Thanks, Dhiren

Hello Dhiren,

Please find the attached outgoing script on cloud side.

Thanks,
Vignesh
Out going script - Cloud.txt (1.8 KB)

Hi @VS57 ,

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”

GroovyHttpClient.groovy (7.6 KB)

Thanks, Dhiren