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 votes
Accepted answer

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 Sign up to answer
Community showcase
Published Wednesday in Jira

Make your Atlassian Cloud products more secure: our NEW admin security guide

Hey admins! I’m Dave, Principal Product Manager here at Atlassian working on our cloud platform and security products. Cloud security is a moving target. As you adopt more products, employees consta...

46 views 0 2
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