Originally asked by Berry Kersten on 09 January 2020 (original question)
I have a problem configuring the following requirement: Set the status of the remote project to Accepted
Example:
GIVEN Local project
AND Status = NEW
THEN sync to remote project
AND set status in remote project to ACCEPTED using the transition âAccepted as a bugâ
Iâve read the documentation on https://docs.idalko.com/exalate/display/ED/Status\+synchronization\+on\+Jira\+Server\#StatussynchronizationonJiraServer\-statusSyncExternal
and followed the instruction âtransition applied to your local issueâ that results in the incoming sync of the remote project:
if (issue.status.name == âNewâ && replica.status.name == âOpenâ) {
workflowHelper.transition(issue, âAccepted as a bugâ)
When trying to sync, I get an error message âScript error details: Cannot get property ânameâ on null object. Error line: Script349.groovy: 8 "
What am I doing wrong?
Thanks!
Berry.Source: Jira Server/Datacenter (old community)
Comments:
Berry Kersten commented on 09 January 2020
Hi Francis Martens (Exalate), yes, but I also tried to execute the logic after the firstSync and I got the same error.
For completeness, the configuration:
Outgoing sync (source):
replica.key = issue.key
replica.type = issue.type
replica.assignee = issue.assignee
replica.reporter = issue.reporter
replica.summary = issue.summary
replica.description = issue.description
replica.labels = issue.labels
replica.comments = issue.comments
replica.resolution = issue.resolution
replica.status = issue.status
replica.parentId = issue.parentId
replica.priority = issue.priority
replica.attachments = issue.attachments
replica.project = issue.project
replica.environment = issue.environment
replica.customFields.âProductâ = issue.customFields.âProductâ
Incoming sync (remote side)
def projectMap = [âTechnical DLM/licensingâ:âDLMâ,âUniface Anywhere Issueâ:âUAâ,âUniface Issueâ:âUNIâ]
if (firstSync) {
// look up project key using the issuetype.name and if not found default to DLM
issue.projectKey = projectMap[replica.type.name] ?: âDLMâ
}
issue.summary = replica.summary
issue.description = replica.description
issue.comments = commentHelper.mergeComments(issue, replica)
issue.attachments = attachmentHelper.mergeAttachments(issue, replica)
issue.environment = replica.environment
issue.customFields.âWorkaroundâ.value = replica.customFields.âProductâ.value?.value
issue.typeName = âBugâ
//if the local issue status is âNewâ and the remote issue status is âOpenâ use âAccepted as a bugâ transition
if (issue.status.name == âNewâ && replica.status.name == âOpenâ) {
workflowHelper.transition(issue, âAccepted as a bugâ)
}
Francis Martens (Exalate) commented on 09 January 2020
The statement 'if (issue.status âŚ) is also executed during the first sync.
What you can do is
if ((issue.status == null || issue.status?.name == "New") &&
replica.status.name == "Open")
Note the â?â
This is a groovy operator allowing to test for null - avoiding a nullpointer exception
Meaning -
issue.status = null
assertNull(issue.status?.name)
Berry Kersten commented on 14 January 2020
Iâve changed the incoming sync to
def projectMap = ["Technical DLM/licensing":"DLM","Uniface Anywhere Issue":"UA","Uniface Issue":"UNI"]
if (firstSync) {
// look up project key using the issuetype.name and if not found default to DLM
issue.projectKey = projectMap[replica.type.name] ?: "DLM"
// old code workflowHelper.transition(issue,"Accepted") ?: "Backlog"
}
issue.summary = replica.summary
issue.description = replica.description
issue.comments = commentHelper.mergeComments(issue, replica)
issue.attachments = attachmentHelper.mergeAttachments(issue, replica)
issue.environment = replica.environment
issue.customFields."Workaround".value = replica.customFields."Product".value?.value
issue.typeName = "Bug"
//if the local issue status is 'New' and the remote issue status is 'Open' use 'Accepted as a bug' transition
if ((issue.status == null || issue.status?.name == "New") &&
replica.status.name == "Open") {
workflowHelper.transition(issue, "Accepted as a bug")
}
and the error is gone!
However, when syncing the issue is not transitioned with âAccepted as a bugâ to status ACCEPTED
I also tried to move
if ((issue.status == null || issue.status?.name == "New") &&
replica.status.name == "Open") {
workflowHelper.transition(issue, "Accepted as a bug")
to the firstsync section, but still no transition.
Iâm not sure how to proceed further.
Francis Martens (Exalate) commented on 15 January 2020
Hi Berry Kersten
Are you sure about the transition name?
(In case the transition doesnât exist or if the proxy user is not permitted the transition, no error will be generated)
I quickly tested a simple script
if(firstSync){
// If it's the first sync for an issue (local issue does not exist yet)
// Set project key from source issue, if not found set a default
issue.projectKey = "NAM"
// Set type name from source issue, if not found set a default
issue.typeName = "Task"
}
issue.summary = replica.summary
issue.description = replica.description
issue.comments = commentHelper.mergeComments(issue, replica)
issue.attachments = attachmentHelper.mergeAttachments(issue, replica)
workflowHelper.transition(issue,"In Progress")
And this work fine.
An alternative is to enable debug logging and inspect the log files.
Berry Kersten commented on 16 January 2020
Hi Francis Martens (Exalate)Thanks. Itâs working now.
Main problem: case sensitivityâŚ
Francis Martens (Exalate) commented on 16 January 2020
Ah yes.
Thanks for confirming.