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

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

2 votes

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.

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...

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")

ok will try creating post function.

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

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

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.

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

359 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you