Originally asked by Dmitrij POPOV on 21 December 2021 (original question)
Context:
- Synchronisation Jira on-premise A to Jira on-premise B.
- On A side Single choice Database Picker cf “AssigneeJIRASW” is connected to side’s B users DataBase.
- During the synchronisation, the value from cf “AssigneeJIRASW” of side A need to fill-in the value of “Assignee” field on the destination B side.
Problem:
- Single choice Database Picker return a Json String value instead of a simple String
Solutions:
Without JIRA API imports:
/* firtssyncs and other fields syncs */
// CF "AssigneeJIRASW" to target "Assignee" field
String AssigneeJIRASW = replica.customFields."AssigneeJIRASW".value?.getAsString()
def defaultUser = nodeHelper.getUserByEmail("default.user@idalko.com")
if (AssigneeJIRASW) {
issue.assignee = nodeHelper.getUserByEmail(AssigneeJIRASW)
} else {
issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: defaultUser
}
issue.reporter = nodeHelper.getUserByEmail(replica.reporter?.email) ?: defaultUser
With JIRA API imports:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
/* firtssyncs and other fields syncs */
// CF "AssigneeJIRASW" to target "Assignee" field
def issueSR = ComponentLocator.getComponent(IssueManager).getIssueObject(replica.key)
def cField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("AssigneeJIRASW")
def cFieldValue = issueSR.getCustomFieldValue(cField)
def defaultUser = nodeHelper.getUserByEmail("default.user@idalko.com")
if(cFieldValue) {
issue.assignee = nodeHelper.getUserByEmail(cFieldValue)
} else {
issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: defaultUser
}
issue.reporter = nodeHelper.getUserByEmail(replica.reporter?.email) ?: defaultUser