I am trying to use Calculated with Components to give me the correct project to clone the ticket to. However, it keeps failing. Here is the code I found to try. I noticed the code was for custom fields, can a system field such as Components be used?
switch (issue.getAsString("Components"))
{
Answer "a": return Project "A"
Answer "B": return Project "B"
}
first of all, that code snippet (which is actually syntactically incorrect) is based on Groovy, which is used only on Jira Server/DC. On Jira Cloud, JMWE uses Nunjucks.
Also, the problem is that the Components field is a multi-valued field (i.e. you can have more than one component selected). What would you like to happen in that case? Calculate the destination Project based on the first component selected? Or are you certain there will never be more than one component selected?
If that is the case, you can use something like this:
{%switch issue.fields.components | first | field("name")%}
{%case "Project A"%}
PA
{%case "Project B"%}
PB
{%endswitch%}
where "Project A" is the component name, and "PA" is the project key of the corresponding project.
I will inform my customer that only one component should be chosen. Thank you very much for the speedy reply!!
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for another question... what If they want to use a different component but go to the same project?
For example:
{%switch issue.fields.components | first | field("name")%}
{%case "Project A"%}
PA
{%case "Project B"%}
PB
{%case "Project C"%}
PA
{%endswitch%}
Can that be done or should be written:
{%switch issue.fields.components | first | field("name")%}
{%case "Project A"%}|| {%case "Project C"%}
PA
{%case "Project B"%}
PB
{%endswitch%}
Where project C is just a different component?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can do either:
{%switch issue.fields.components | first | field("name")%}
{%case "Project A"%}
PA
{%case "Project B"%}
PB
{%case "Project C"%}
PA
{%endswitch%}
or:
{%switch issue.fields.components | first | field("name")%}
{%case "Project A"%}{%case "Project C"%}
PA
{%case "Project B"%}
PB
{%endswitch%}
(note that the two case statements need to be on the same line in that case, with no space between them)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.