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

Javier Portillo
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.
February 27, 2012

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
Answer accepted
Jobin Kuruvilla [Adaptavist]
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.
February 27, 2012

How are you getting the project in the method?

Javier Portillo
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.
February 27, 2012

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

Jobin Kuruvilla [Adaptavist]
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.
February 27, 2012

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.

Javier Portillo
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.
February 27, 2012

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?

Jobin Kuruvilla [Adaptavist]
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.
February 27, 2012

Try:

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

0 votes
Hasnae E July 31, 2017

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.

0 votes
Javier Portillo
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.
February 27, 2012

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

Javier Portillo
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.
February 28, 2012

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?

Javier Portillo
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.
February 29, 2012

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

Thanks again!!

Suggest an answer

Log in or Sign up to answer