JMWE Select component depents of text in issue description

Artur Sox November 14, 2018

Hello all, please help to solve the problem.

I use JMWE add-on

I have 3 components (componentA,componentB,componentC)

I have 3 issues which have constants in their descriptions

issue A:  description containce text "cityA"

issue B:  description containce text "cityB"

issue C:  description containce text "cityC"

how to select componentA for all issues which have text "cityA" ?

4 answers

0 votes
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 14, 2018

If you want to set the Components field automatically during issue creation based on the Description, you can use a Set Field Value post-function on the Create transition, with a Groovy Expression value such as:

if (issue.get("description")?.contains("cityA"))
  return "componentA"
if (issue.get("description")?.contains("cityB"))
  return "componentB"
//etc for the other cities 

return null; //if description contains none
Artur Sox November 15, 2018

Thx. Gonna try it

0 votes
Artur Sox November 14, 2018

I have script like this, but when i use it in JMWE postfunction issue create it did not selects right component

 

import com.atlassian.jira.project.Project
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField

MutableIssue issue = issue

def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def project = issue.getProjectObject()
def compA = projectComponentManager.findByComponentName(project.getId(), "componentA");
def compB = projectComponentManager.findByComponentName(project.getId(), "componentB");
def compC = projectComponentManager.findByComponentName(project.getId(), "componentC");

if(compA != null && issue.getAsString("description").contains ("Location: cityA")){
issue.setComponent([compA])
}

if(compB != null && issue.getAsString("description").contains ("Location: cityB")){
issue.setComponent([compB])
}

if(compC != null && issue.getAsString("description").contains ("Location: cityC")){
issue.setComponent([compC])
}

 

Maybe I do someth wrong ?

0 votes
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 14, 2018

Hi @Artur Sox

you didn't specify if you are on Jira Server or Cloud. 

Artur Sox November 14, 2018

jira server

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 14, 2018

And at what point would you like to set the component based on the description? During issue creation? During another transition?

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 14, 2018

Hello @Artur Sox

You can use the post-function in the JMWE plugin

here's the docs

https://innovalog.atlassian.net/wiki/spaces/JMWE/pages/68878480/Set+field+value

You can choose the component field and use the groovy expression to check if the description contains the string "cityA" and then set the relevant component.

Artur Sox November 14, 2018

Yeap, i know. But how to write correct script ?

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 14, 2018

Please see here

https://innovalog.atlassian.net/wiki/spaces/JMWE/pages/113311862/Accessing+the+fields+of+an+issue

 

You can access the description field and check if the string contains the value "cityA"

Suggest an answer

Log in or Sign up to answer