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.
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 ,
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then the first line becomes:
{%set projectName = issue.fields["Project Name"].value %}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@David Fischer 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Inna S
You can try to get a project key by project name in a JMWE post function, by following these steps:
{% 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Inna S
Try this one please
{% set projectName = "Your Project Name" %}
{% set allProjects = jira.searchProjects({}) %}
{% set project = allProjects | first("name", projectName) %}
{{ project.key }}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
-- wrong place --
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.