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

This widget could not be displayed.

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];

This widget could not be displayed.

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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

97 views 1 0
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