How to get project name through groovy script to use under script runner plugin

Nagmani Nagmani January 31, 2012

HOw to get project name under "title" field and its summary under content field of a page while creation of automatic page using script post function under a create issue.

1 answer

1 accepted

4 votes
Answer accepted
JamieA
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.
January 31, 2012

Project name is

issue.projectObject.name

and summary is:

issue.summary

You already have the code for creating the page in confluence, so you just need to plug those values in.

Nagmani Nagmani January 31, 2012
I AM GETTING THIS ERROR:
javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: issue for class: Script37
issue should be written as issue or name of the issue...
JamieA
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.
January 31, 2012

issue is correct if you are running it from a post-function. If you are running it from the admin panel for testing you will need to get an issue yourself, eg:

def componentManager = ComponentManager.getInstance()
def issue = componentManager.getIssueManager().getIssueObject("JRA-1306")

Nagmani Nagmani January 31, 2012

ok will try creating post function.

Nagmani Nagmani January 31, 2012

Basically I have added custom field as "project name" under the create issue.

so I just want to fetch the value inside that customfield and place it as the title of mypage.

if u can tell me how to getvalue of that custom field i think the work would be done for me.

Thanks

JamieA
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.
January 31, 2012

Why didn't you say project name was a custom field?

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

def cf = customFieldManager.getCustomFieldObjectByName("Project Name")
issue.getCustomFieldValue(cf) // project name

Nagmani Nagmani February 1, 2012

Actually I was first trying out with the project name of every project name I create in jira but that was not serving my purpose as I wanted to have different pages for every different issue under the same project. So I made a customfield to capture the unique project name for each issue.

Thanks for the answer as it is exactly what I wanted to get.

Rumceisz June 27, 2012

Hi Jamie,

perhaps my need is similar to this:

I have a custom field which options are the current project names of the Jira instance. But the project leads often change the name of the projects so - there about 200 projects we handle - it is cumbersome to update the options regularly.

Can you please send me a groovy script which result the list of the current project names (not keys!)? I have Behaviour plugin, so I thought I will add this script to this custom field in behaviour.

With Scripted field it would be the most simplest of course but we have an older version of Script Runner because our version 4.3 Jira.

Can you please suggest?

Thanks in advance!
Rumi

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events