Set Project Lead with Script Runner

Deleted user March 16, 2018

Hello,

 

I trying write code in groovy script runner to create project from post function level in JIRA. Everything going well, but i can't find any solution to change Project Lead for project. I saw that possible is change default assignee, but i can't find any information about Project Lead. Meybe anyone found solution for this. I just need example for specific function. I will be very grateful for help!

Regards,

Wojciech Miecznikowski

1 answer

1 accepted

1 vote
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 16, 2018
Deleted user March 19, 2018

Big thanks! This is it what i need. I just have problems with implementing this method:

[Static type checking] - Cannot find matching method com.atlassian.jira.project.ProjectManager#updateProject(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object). Please check if the declared type is right and if the method exists. 

Do you have any idea? 

Deleted user March 19, 2018

simple example:

import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager

def originalproject = "TESTOR"
def name = "AAA"
def decsription = "test"
def leadkey = "102205"
def assigneeType = "Unassigned"

ProjectManager.updateProject(Project originalProject,Long name,String description,String leadKey,String url,Long assigneeType)

return:

The script could not be compiled:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script808.groovy: 10: The current scope already contains a variable of the name name
 @ line 10, column 59.
   (Project originalProject,Long name,Strin
                                 ^

Script808.groovy: 10: The current scope already contains a variable of the name assigneeType
 @ line 10, column 114.
   tring leadKey,String url,Long assigneeTy
                                 ^

 

If i comment name and assigneetype i got: Cannot find matching mathod

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 19, 2018

I did not check the code by it must be like this:

import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager

import com.atlassian.jira.project.AssigneeTypes

def originalproject = ComponentAccessor.getProjectManager().getPrjectObjByKey("TESTOR")
def name = "AAA"
def decsription = "test"
def leadkey = "username"
def assigneeType = "Unassigned"

ComponentAccessor.getProjectManager().updateProject(originalProject name,description,leadKey, url, AssigneeTypes.UNASSIGNED)

You should provide respect paramteres types.

Deleted user March 19, 2018

Thanks! I still learning of groovy. I see that you have small mistake in def of original project. Should be "getProjectManager()" and must have:
"import com.atlassian.jira.component.ComponentAccessor" and "," before name in last line. Anyway. I used a code:

import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.AssigneeTypes
import com.atlassian.jira.component.ComponentAccessor

def originalproject = ComponentAccessor.getProjectManager().getProjectObjByKey("TESTOR")
def name = "AAA"
def decsription = "test"
def leadkey = "102205" // this is username in my JIRA instance
def assigneeType = "Unassigned"

ComponentAccessor.getProjectManager().updateProject(originalProject,name,description,leadKey,url,assigneeType.UNASSIGNED)

and after run i have:
groovy.lang.MissingPropertyException: No such property: originalProject for class: Script879
at Script879.run(Script879.groovy:12)

Compiler said:

image.png

any idea? 

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 19, 2018

Yes, the name of variable are different from declaration and passing the the procedure. 

import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.AssigneeTypes
import com.atlassian.jira.component.ComponentAccessor

def originalproject = ComponentAccessor.getProjectManager().getProjectObjByKey("TESTOR")
def name = "AAA"
def description = "test"
def leadkey = "102205" // this is username in my JIRA instance
def url = "http://google.com"

ComponentAccessor.getProjectManager().updateProject(originalproject,name,description,leadkey,url,assigneeType.UNASSIGNED)
Deleted user March 19, 2018

Ok. Foolishly mistakes in declaration... When i trying to use your code i have this:

groovy.lang.MissingPropertyException: No such property: assigneeType for class: Script885 at Script885.run(Script885.groovy:12)

so I change last line like this:

def assigneeType = "102205" as long

ComponentAccessor.getProjectManager().updateProject(originalproject,name,description,leadkey,url,assigneeType)

and Script working but in project i can see "Please select a Default Assignee". It looks that this method have problem with long "Unassigned"? Do you know something about this?

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 19, 2018
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.AssigneeTypes
import com.atlassian.jira.component.ComponentAccessor

def originalproject = ComponentAccessor.getProjectManager().getProjectObjByKey("TESTOR")
def name = "AAA"
def description = "test"
def leadkey = "102205" // this is username in my JIRA instance
def url = "http://google.com"

ComponentAccessor.getProjectManager().updateProject(originalproject,name,description,leadkey,url,AssigneeTypes.UNASSIGNED)
Deleted user March 19, 2018

Thank you very much!

Tom March 3, 2020

I'm sorry to revive this thread, but I have a problem to set the lead.
In my case this is entered as text, but not as recognized user (AD). I have already tried different spelling variants.

What is the solution here?

Nitish Sajwan February 3, 2021

Hi Tom,

You might need to enter the userid instead of username.

 

Regards,

Nitish

Tom February 4, 2021

Hello Nitish,

i have already solved my problem, but thanks for your advice.

 

https://community.atlassian.com/t5/Jira-questions/solved-Set-Project-Lead-with-Groovy-Script-Runner/qaq-p/1322400

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events