Forums

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

created "N" issue based on multiselect field

Dante Labate December 19, 2018

I have a need to create issues related to the current issue based on the number of items selected in a multiselect field (if 3 options are selected, 3 issues [with the summary being the name of the options] must be created) and related to the current issue.

I thought about using the "Clones an issue, and links" of Script Runner, but from what I understood, it would only issue one issue (it does not take into account the quantity of item selected).

I also thought about using the "Create issues and subtasks" of JWT, it has the option to create based on a stringlist, but I came across another problem, the value stored in the multiselector field is not a list .. in fact it's a single string separated by ###.

example: apple###orange###banana

(not counting that I still do not know how to put the value of selections as a summary).

Anyone have any suggestions?

2 answers

0 votes
Thorsten Letschert [Decadis AG]
Atlassian Partner
December 19, 2018

Hi @Dante Labate,

you can still use JWT. Just use an expression like this (where nnnnn has to be replaced by the field code you're referring to):

toStringList(%{nnnnn},"###")

 It'll return a list of elements representing the strings between your hashes.

Afterwards, you're able to reference the single values by just adding:

^%

Given your example - apple###orange###banana - you'll receive three issues with the summaries

  • apple
  • orange
  • banana

Cheers,
Thorsten

Dante Labate December 19, 2018

@Thorsten Letschert [Decadis AG]

 

Creation worked (it creates the issue quantity according to the selection made).

 

my selection field has the id 17203

toStringList(%{17203},"###")

 

but I did not understand how to make the summary the value of each selection.

Thorsten Letschert [Decadis AG]
Atlassian Partner
December 20, 2018

Hi @Dante Labate,

like shown here (https://apps.decadis.net/display/JWT/Create+a+story+for+each+component+in+an+epic), you should use the placeholder ^%.

You can use it in every field, not just the summary. In the example mentioned above it's used for the summary as well as the description.

jwt_placeholder.JPG

Cheers,
Thorsten

0 votes
Elifcan Cakmak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 19, 2018

Hello,

You need to write a custom script and add it to your workflow as a postfunction. A script like this would work:

import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult;
import com.atlassian.jira.bc.issue.IssueService.IssueResult;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.issuetype.IssueType;
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def issue = issueManager.getIssueObject("SP-13")
def user = authenticationContext.getLoggedInUser()
def issueFactory = ComponentAccessor.getIssueFactory()
def issueService = ComponentAccessor.getIssueService()
def pid = new Long(10000)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customfield = customFieldManager.getCustomFieldObject("customfield_10837")

def customfieldValues = issue.getCustomFieldValue(customfield)

for (value in customfieldValues) {
def newtask = issueFactory.getIssue()
newtask.setProjectId(pid)
newtask.summary = value
newtask.description = "issue description"
newtask.setIssueTypeId("10002")
newtask.setAssigneeId("elifcan")
newtask.setReporterId("elifcan")
newtask = issueManager.createIssueObject(user, newtask)

newtask.store()
issueLinkManager.createIssueLink(issue.getId(), newtask.getId(), 10000L, 1, user)

}

Of course, you will need to change the necessary information like issuetype Id, project Id, etc.

Regards,

Elifcan

Dante Labate December 19, 2018

@Elifcan Cakmak

Tks

I will do tests and return!

Suggest an answer

Log in or Sign up to answer