Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

In JMWE can Calculated be used with Components?

Mark Williams October 17, 2023

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"

}

1 answer

1 accepted

1 vote
Answer accepted
David Fischer
Community Champion
October 17, 2023

Hi @Mark Williams 

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.

Mark Williams October 17, 2023

I will inform my customer that only one component should be chosen. Thank you very much for the speedy reply!!

Mark

Mark Williams October 26, 2023

@David Fischer 

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?

David Fischer
Community Champion
October 26, 2023

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)

Like Mark Williams likes this

Suggest an answer

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

Atlassian Community Events