How to create a Text Custom Field including as default value the current project name?

Hi there,

I would like to create a jira plugin consisting on a text custom field with its default value equal to the current project name.

I have tried to use the getValueFromIssue but i just works on the issue editing page. In the issue creation page it does not work.

Please any help.

3 answers

1 accepted

0 vote

How are you getting the project in the method?

One of the parameters of the getValueFromIssue method is an issue. I get the project by using issue.getProjectObject().getName(). My problem is that in the issue creation page because the issue is not still created

Eaxctly. But you can get the project from the projectId which is available in the Create Scenario. I think it is there in the ActionContext. Have a look.

Yes, it seems that ActionContext class is what I need but I have tried it by using:

Map session=ActionContext.getSession();
Long projectID=(Long)session.get(SessionKeys.SELECTED_PROJECT);

And I always get a null value for the session. Any idea?

Try:

String[] ids = (String[]) ActionContext.getParameters().get("pid");
String pid = ids[0];

Yes, these last two line seems to work perfectly!!

In ids[0], the current project id is store even when I change the Project in Jira

Thanks a lot!!

I have a new problem. The last two lines give me the current project ID in the new issue and modify issue pages. However, when I try to clone an issue, I get a NullPointer Exception. Any idea?

Finally the last problem has been resolved by assigning a predefined default value when ids[] is null or length=0

Thanks again!!

Hi!

Does ActionContext.getParameters().get("pid") still work in Jira7.2? because i've used it exactly as you said, i mean 

String[] ids = (String[]) ActionContext.getParameters().get("pid");
String pid = ids[0];

But it gives me a 500error.

Is there any other way to get the current project's id? 

 

Thanks.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,189 views 13 19
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot