Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,499,073
Community Members
 
Community Events
179
Community Groups

How to get a project key by project name in JMWE post function?

Hi, 

I'm trying to create an issue in a different project based on a field value in the issue.

The value matches the project name, but the issue creation expects the project key.

Is there a way to get the project key by project name and then pass it to the issue creation in JMWE function?

Thank you.

2 answers

1 accepted

2 votes
Answer accepted

Hi @Inna S ,

you can use code like this:

{%set projectName = "Test"%}
{%set projectKey = "/rest/api/2/project/search?query=:name" | callJira(
params={
name:projectName
}
) | field("values") | find("name",projectName) | field("key")
%}
{{projectKey}}

Hi @David Fischer _Appfire_ , 

thank you for this tip.

But the name of the destination project is in one of the issue fields. 

I've tried several ways of referencing it, but to no avail.

Say, the project name is in the field 'Project Name', that is a drop down list type of the field. 

How do I get it into the 'set' statement?

Then the first line becomes:

{%set projectName = issue.fields["Project Name"].value %}
Like Kelly Arrey likes this

It still comes empty.

You need to test step by step. 

First check that you're getting the project name right, exactly as it is in the project. Test this:

{%set projectName = issue.fields["Project Name"].value %}
**{{projectName}}**

 This will allow you to check that you're getting the project name without leading or trailing spaces. Then compare it with the name of the project - note that case must also match. 

Then replace the first line of the script I provided earlier with the actual project name, to make sure you then get the project key. 

Let me know how it goes. 

Like Kelly Arrey likes this

@David Fischer _Appfire_ This fisrt line comes empty.

When I post the actual value, the script works all right. But I can't seem to get the value of this custom field from the issue.

The field is of the type 'drop down' options.

Thank you very much for trying to help, @David Fischer _Appfire_ 

When you test this:

{%set projectName = issue.fields["Project Name"].value %}
**{{projectName}}**

What do you get? If you get just **** then it means you're not accessing the field properly. Please check using the "Issue Fields" help tab at the bottom of the editor to check how to access the Project Name field.

Great! This was a custom field so it expects the reference in the form of ... customfield_xxxx, and not the display name of the field.

This helper is really great tool.

 

Thank you very much for your help, @David Fischer _Appfire_ !

Actually, you can refer to the field by name, but you need to make sure the name is exactly accurate - including case, leading/trailing whitespace, etc.

Also, if the solution works, can you "accept" the answer so that other community members can benefit from it? Thanks.

Like # people like this
0 votes

Hi @Inna S 

You can try to get a project key by project name in a JMWE post function, by following these steps:

  • Open the workflow and click on the transition.
  • Click 'Post Functions' and 'Add Post Function'.
  • Choose 'Create Issue(s)' and click 'Add'.
  • In the 'Project' field, use this Nunjucks template:


{% set projectName = "Your Project Name" %}
{
% set project = issue.fields.project | first("name", projectName) %} {{ project.key }}


Replace "Your Project Name" with the actual name then Configure the issue creation settings.


Click 'Add' to save the post function.


This will create an issue in the specified project based on the project name.

@Oday Rafeh but I'm not looking for the current issue project key. 

Hi @Inna S 

Try this one please 

{% set projectName = "Your Project Name" %} 
{% set allProjects = jira.searchProjects({}) %}
{% set project = allProjects | first("name", projectName) %}
{{ project.key }}
Like Inna S likes this
Like Oday Rafeh likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events