Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Can you get a project lead using the project key in groovy?

Tim Perrault May 25, 2018

I have a custom field (project picker) and I want to grab the project lead of the selected project in that field. From that field I figured I could use the project KEY to search and grab the project lead. I have the project key, but I'm having a hard time finding a starting point for using that to search grab the project lead. Any advice?

 

Thanks,

Tim

1 answer

1 accepted

2 votes
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.
May 25, 2018

Hello,

You could use

ComponentAccessor.getProjectManager().getProjectObjByKey("projectkey").getProjectLead()

Tim Perrault May 25, 2018

Is there a way to use a variable instead of the actual project key? I was trying the code below, but it doesn't seem to work. Cannot invoke method getProjectLead() on null object

 

def np =customFieldManager.getCustomFieldObjectByName("Needed Project")
def npval = issue.getCustomFieldValue(np)
def text = npval.toString()
String newString = text.replaceAll("Project: ", "")
def project = ("\""+newString+"\"")
def lead = ComponentAccessor.getProjectManager().getProjectObjByKey(project).getProjectLead()

  

And thanks so much you have been super helpful!

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.
May 25, 2018

the project variable must equal to the project key. For example, KEY. In your case I guess it is something else. Could add log.error("project: " + project) and paste here the output in atlassian-jira.log file?

 

def np =customFieldManager.getCustomFieldObjectByName("Needed Project")
def npval = issue.getCustomFieldValue(np)
def text = npval.toString()
String newString = text.replaceAll("Project: ", "")
def project = ("\""+newString+"\"")
log.error("project: " + project)
def lead = ComponentAccessor.getProjectManager().getProjectObjByKey(project).getProjectLead()
Tim Perrault May 26, 2018

Thank you so much! That got me to see the issue. I think it was the quotes I was adding to "newString". I took out project and put in newString ( getProjectObjByKey(newString) ) and it returned the project lead.

Thanks again,

Tim

Suggest an answer

Log in or Sign up to answer