Assign project default as issue reporter

Originally asked by last knight on 23 January 2020 (original question)


When syncing an issue to another JIRA server, how can I assign the issue reporter in destination as the project default or component leader ?Source: Jira Server/Datacenter (old community)


Answer by last knight on 27 January 2020

Thanks Francis,

I used the below code:

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   = nodeHelper.getProject(replica.project?.key)?.key ?: "TEST"
   issue.projectKey = replica.customFields."Vendor Name"?.value?.value
   // Set type name from source issue, if not found set a default
   issue.typeName     = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Task"
}
issue.summary      = replica.summary
issue.description  = replica.description
issue.comments     = commentHelper.mergeComments(issue, replica)
issue.attachments  = attachmentHelper.mergeAttachments(issue, replica)
//issue.reporter     = nodeHelper.getUserByUsername(replica.assignee?.username)
issue.labels       = replica.labels
def targetProject = nodeHelper.getProject(issue.projectKey)
def targetComponent = nodeHelper.getComponent(replica.project.name, targetProject)
if (!targetComponent) {
    targetComponent = nodeHelper.createComponent(
        issue,  replica.project.name, replica.project.key, null, "PROJECT_DEFAULT"
        )

}
issue.components += targetComponent
issue.customFields."Autoliv Contact"?.value = replica.assignee  
issue.due = replica.due

// find the correct project, issue doesn't exist yet
def jProject        = ComponentAccessor.projectManager.getProjectByCurrentKey(issue.projectKey)
    
// set the assignee to the project lead, or admin if lead is not set
issue.reporter = nodeHelper.getUser(jProject.lead?.key ?: "admin")


Status.receive()

I got below error:

Script error details: No such property: ComponentAccessor for class: Script337. Error line: Script337.groovy:28

Regards


Comments:

Francis Martens (Exalate) commented on 27 January 2020

Ah - you need to import the class

Add in the first line

import com.atlassian.jira.component.ComponentAccessor

Answer by last knight on 11 February 2020

it is working now … I haven’t seen your last comment :smile:


Comments:

Francis Martens (Exalate) commented on 11 February 2020

Alright - I’m a bit lost with the different comments disguished as answer. Assuming you’re all set?

Answer by last knight on 11 February 2020

sorry for late reply

I got below error:

Script error for issue TECHNIA-3. Details: No such property: jProject for class: Script47. Error line: Script47.groovy:14

I used below syntax in incoming sync in destination JIRA server:

issue.reporter = nodeHelper.getUser(jProject.lead?.key ?: "admin")  
issue.assignee = nodeHelper.getUser(jProject.lead?.key ?: "admin")

Answer by Francis Martens (Exalate) on 23 January 2020

A way to do this is as follows

if(firstSync && replica.project.key == "AN"){
   issue.projectKey   = "HAS"
   issue.typeName     = "Task"
   
    // find the correct project, issue doesn't exist yet
    def jProject        = ComponentAccessor.projectManager.getProjectByCurrentKey(issue.projectKey)
    
    // set the assignee to the project lead, or admin if lead is not set
    issue.assignee = nodeHelper.getUser(jProject.lead?.key ?: "admin")
} 

Is this clear?


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.