Answer by Bjørnar Nybruket on 11 May 2022
I want to share my entire Incoming script, in case there is something wrong somewhere else in the script.
def typeMapping = [
// "remote issue type" : "local issue type"
"Story" : "Historie",
"Epic" : "Gruppering",
"Task" : "Oppgave",
"Bug" : "Feil",
"Sub-task" : "Deloppgave"
]
def remoteTypeName = replica.type?.name
def localType = typeMapping[remoteTypeName] ?: remoteTypeName
if(firstSync){
// Set type name from source entity, if not found set a default
issue.projectKey = "EUR"
issue.typeName = nodeHelper.getIssueType(localType)?.name?: "Oppgave"
}
issue.summary = replica.summary
issue.description = replica.description
//issue.comments = commentHelper.mergeComments(issue, replica)
issue.attachments = attachmentHelper.mergeAttachments(issue, replica)
//Dates
issue.due = replica.due
issue.customFields."Start Date" = replica.customFields."Start Date"
// remoteIssueUrl is provided in the incoming sync script
issue.customFields."RemoteIssue".value = remoteIssueUrl
//Checking for ParentID for Subtasks
if(firstSync && replica.parentId){
issue.typeName = "deloppgave" //Make sure to use the right subtask type here.
def localParent = nodeHelper.getLocalIssueFromRemoteId(replica.parentId.toLong())
if(localParent){
issue.parentId = localParent.id
} else {
throw new com.exalate.api.exception.IssueTrackerException("Subtask cannot be created: parent issue with remote id " + replica.parentId + " was not found. Please make sure the parent issue is synchronized before resolving this error" )
}
}
/*
User Synchronization (Assignee/Reporter)
Set a Reporter/Assignee from the source side, if the user can't be found set a default user
You can use this approach for custom fields of type User
*/
def remoteAssignee = nodeHelper.getUserByEmail(replica.assignee?.email)
if (nodeHelper.isUserAssignable(issue.projectKey, remoteAssignee)) {
issue.assignee = remoteAssignee
}
else {
issue.assignee = null
}
/*
def defaultUser = nodeHelper.getUserByEmail("ks@septemberbi.no")
issue.reporter = nodeHelper.getUserByEmail(replica.reporter?.email) ?: defaultUser
issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: defaultUser
*/
/*
Comment Synchronization
Sync comments with the original author if the user exists in the local instance
*/
issue.comments = commentHelper.mergeComments(issue, replica){ it.executor = nodeHelper.getUserByEmail(it.author?.email) }
//Sync status for Epics
if (issue.typename == "Gruppering") {
// ["remote status name" : "local status name"]
def epicStatusMap = [
"On Hold" : "Pending",
"QA Test" : "For testing",
"UA Test" : "For testing",
"Approved" : "For testing",
"Not Approved" : "For testing",
"To Do" : " Gjøremål",
"in Progress" : "under arbeid",
"Backlog" : "Gjøremål",
"Done" : "Ferdig",
]
def epicStatusName = replica.customFields."Epic Status".value
issue.setCustomFieldValue("Epic Status", epicStatusMap[epicStatusName] ?: "Gjøremål")
} else {
//Sync for all other statuses
// ["remote status name" : "local status name"]
def statusMap = [
"On Hold" : "Pending",
"QA Test" : "For testing",
"UA Test" : "For testing",
"Approved" : "For testing",
"Not Approved" : "For testing",
"Backlog" : "Gjøremål",
"in Progress" : "under arbeid",
"To Do" : "Gjøremål",
"Done" : "Ferdig"
]
def remoteStatusName = replica.status.name
issue.setStatus(statusMap[remoteStatusName] ?: "Gjøremål")
Epic.receive()
}
//Custom Fields
Epic.receive()
Comments:
Bjørnar Nybruket commented on 11 May 2022
Here is the incoming remote replica:
{
"version": {
"major": 1,
"minor": 14,
"patch": 0
},
"hubIssue": {
"components": [],
"attachments": [],
"voters": [],
"customFields": {},
"eventTriggerContext": {},
"description": "Agreements in place?",
"project": {
"idStr": "10001",
"key": "DPR",
"name": "Dataplatform and Reporting",
"versions": [],
"components": []
},
"watchers": [],
"fixVersions": [],
"id": "10075",
"key": "DPR-9",
"summary": "SLA Agreement",
"comments": [],
"internalMap": {},
"reporter": {
"key": "62309bc0442e0e0069eca714",
"active": true,
"email": "x",
"displayName": "x"
},
"priority": {
"id": "3",
"name": "Medium"
},
"parentId": "10074",
"labels": [],
"customKeys": {
"Epic Link": {
"id": 10074,
"key": "DPR-8"
}
},
"workLogs": [],
"issueType": {
"id": "10001",
"name": "Story"
},
"assignee": {
"key": "60057042e64c95006fbde104",
"active": true,
"email": "x",
"displayName": "x"
},
"affectedVersions": [],
"entityProperties": {},
"status": {
"id": "10006",
"name": "To Do",
"description": "Ready to be done",
"category": {
"id": 2,
"key": "new",
"name": "To Do"
}
}
},
"issueUrl": "https://x.atlassian.net/browse/DPR-9"
}