Answer by Jorden Van Bogaert on 10 March 2022
Hi Moogambigai G R
You’ll need to create/use a custom field to store the remote issue key. On the destination side, you add the Jira Issue key in the outgoing sync, while on the source side you add the information to the custom field. Example:
B Side (OUTGOING)
replica.key = issue.key
A Side (INCOMING)
//Change <Remote Issue Key> with the name of your field
issue.customFields."Remote Issue Key" = replica.key
This will populate the field whenever side B has had an update first. If you want side B to send back the Jira key immediately after create, you can add the following to side B’s incoming sync at the bottom.
:information: Make sure your outgoing sync on side B passes the issue key as per code block 1.
Side B (INCOMING)
if(firstSync)
{
syncHelper.syncBackAfterProcessing()
}
Hope this helps
Kind regards
Jorden
Comments:
Moogambigai G R commented on 10 March 2022
Hi Jorden Van Bogaert
Thanks for the answers.
yes, we have tried the above configuration, here we are syncing two projects in same instance and also its a two way sync.
There we are facing issues, in destination side we are setting default value for some custom fields even though in source side value is different if we put sync back after processing, once record is exalated its again sync back to source and changing all fields.
so that’s why is there any other possible way to get remote key.
Regards,
Moogambigai G R
Jorden Van Bogaert commented on 10 March 2022
Hi Moogambigai G R
If the fields have different values, and you don’t want the values to overwrite the source side, you should simply remove those fields from being send to the other side by removing them from the outgoing sync.
Or you can alter your incoming sync to only process certain fields and not all.
If you don’t do either of these two, you’ll values be overwritten anyways whenever the remote side has any update to tickets.
Kind regards
Jorden
Moogambigai G R commented on 10 March 2022
Hi Jorden Van Bogaert
Is it possible? whenever I first exalated the issues in source side it should sync back only remote key from destination side, after in same destination record if i change or update something, source side should be get update?
Below is the current configuration currently using, I have shared same code only, but we have more fields, please help on this.
Outgoing Script:
A->B
if (issue.project.key == "DAR" && issue.typeName == "Defect")
{
replica.key = issue.key
replica.type = issue.type
replica.customFields."10706" = issue.customFields."10706"
replica.customFields."10134" = issue.customFields."10134"
}
B->A
else if (issue.project.key == "OEM" && issue.typeName == "Acquired Product Defect")
{
replica.key = issue.key
replica.type = issue.type
replica.customFields."17002" = issue.customFields."17002"
replica.customFields."17003" = issue.customFields."17003"
}
Incoming Script:
sync A->B
if(replica.project.key == "DAR" && replica.type.name == "Defect") //sync A -> B
{
issue.projectKey = "OEM"
def issueTypeMapping = [
"Defect" : "Acquired Product Defect"
]
issue.typeName = issueTypeMapping[replica.type?.name] ?: "Acquired Product Defect"
issue."17003" = "Alexandra"
issue."17002" = replica."10706"
if(firstSync){
syncHelper.syncBackAfterProcessing()
}
}
sync B->A
else if(replica.project.key == "OEM" && replica.type.name == "Acquired Product Defect") {
//sync B -> A
issue.projectKey = "DAR"
def issueTypeMapping = [
"Acquired Product Defect" : "Defect"
]
issue.typeName = issueTypeMapping[replica.type?.name] ?: "Defect"
issue."10134" = "Alexandra"
issue."10706" = replica."17002"
issue.customFields."OEM Sync ID".value = replica.key
}
Regards,
Moogambigai G R
Jochim Van Dijck commented on 10 March 2022
Hi Moogambigai G R
In the incoming sync you can check if the local issue already has this custom field for the external key set, and if it has, sync the incoming changes.
If the issue does not have the external key, but the replica does, then we know this is the first sync back and we can set the external key custom field, but nothing else.
In code it could look something like this:
if (issue.customFields."OEM Sync ID".value == replica.key) {
// sync all changes, this is not the first sync back
} else {
issue.customFields."OEM Sync ID".value = replica.key
}
Regards,
Jochim
Moogambigai G R commented on 11 March 2022
Hi Jochim Van Dijck
Yes its working when I first exalated record in source side and its syncing back destination key.
But when I when created record in destination side and sync to source side, its not working it throws error, there because its not satisfiying with below condition destination incoming sync.
else if(replica.project.key == "OEM" && replica.type.name == "Acquired Product Defect")//sync B -> A
{
issue.projectKey = "DAR"
def issueTypeMapping = [
"Acquired Product Defect" : "Defect"
]
issue.typeName = issueTypeMapping[replica.type?.name] ?: "Defect"
if (issue.customFields."OEM Sync ID".value == replica.key)
{
issue."11030" = replica."17004" //Defect Change Type//OEM Defect Change Type
issue."10113" = replica."17006" //Customer Severity//OEM Customer Severity
}
else
{
issue.customFields."OEM Sync ID".value = replica.key
}}
Regards,
Moogambigai G R
Moogambigai G R commented on 16 March 2022
Hi there,
Is there any update?
Regards,
Moogambigai G R
Jorden Van Bogaert commented on 17 March 2022
Hi Moogambigai G R
You can use if(firstSync) to differentiate the conditions.
firstSync will be “true” if a local issue does not exist yet. In that case, you probably want to receive all data from the other side, when firstSync is false (local issue already exists), then you want to use the condition as per Jochim’s response.
Hope this helps.
Kind regards
Jorden
Moogambigai G R commented on 17 March 2022
Hi Jorden Van Bogaert
Can you provide sample configuration to differentiate the condition?
Regards,
Moogambigai G R
Jorden Van Bogaert commented on 17 March 2022
Hi Moogambigai G R
Looking at Jochim’s code, I simply changed first condition to include the firstSync, that should do the trick I think.
if (issue.customFields."OEM Sync ID".value == replica.key || firstSync) {
// sync all changes, this is not the first sync back
} else {
issue.customFields."OEM Sync ID".value = replica.key
}
Moogambigai G R commented on 22 March 2022
Hi Jorden Van Bogaert
Thanks for you answer,
We have existing records that also should update with destination key but with above configuration is not possible because only new records its updating. So I have tried below configuration(scripted field (script runner)).
I am able to see the destination key, but here I changed exalate connection configuration has “Remote link panel” instead of “Sync Panel” only i am to show the destination key.
Here also we used “sync panel” before but after i changed to “Remote link panel” it only appears for new issues not able to get existing issues.
Is there any possible to get the destination record with below configuration instead of using “remote link” configuration.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.link.RemoteIssueLinkManager
import com.atlassian.jira.issue.Issue
// Get the components
def issueManager = ComponentAccessor.issueManager
def issueLinkManager = ComponentAccessor.issueLinkManager
def remoteIssueLinkManager = ComponentAccessor.getComponent(RemoteIssueLinkManager)
// Define the params to get an issue and filter the issue links by type
//final issueKey = 'DAR-526120'
//final issueLinkTypeName = 'Exalated with'
// Get the issue
//def issue = issueManager.getIssueByCurrentKey(issueKey)
Issue issue = issue
issueKey = issue.getKey()
/*//def issue = issueManager.getKey()
// Get the issue links to other issues
//def issueLinks = issueLinkManager.getOutwardLinks(issue.id)
//def filteredLinks = issueLinks.findAll { it.issueLinkType.name == issueLinkTypeName}
// Collect the HTML links pointing to the linked issues
def baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)
def linkedIssuesHtmlLinks = filteredLinks.collect { issueLink ->
def issueUrl = "${baseUrl}/${issueLink.destinationObject.key}"
"[${issueLink.destinationObject.key}](${issueUrl})"
}*/
// Collect the HTML links pointing to the remote links
def remoteLinks = remoteIssueLinkManager.getRemoteIssueLinksForIssue(issue)
def remoteLinksHtml = remoteLinks.collect {remoteLink ->
"[${remoteLink.title}](${remoteLink.url})"
}
// Display the links
"""
${remoteLinksHtml.collect {"* ${it}
" }.join('\n')}
"""
Regards,
Moogambigai G R