Use multiselct to create issues in multiple projects

Eric Collins July 23, 2017
I am trying to create issues based on the selection of a multiselect field. For example: select Apple. Banana, and sandwich in task creation the result would be a task created in project Apple, banana, and sandwich. The multiselect is an Insight multiselect field.

5 answers

0 votes
Eric Collins August 24, 2017

please see above @Mathias Edblom.

Mathias Edblom August 31, 2017

Hi Eric,

Where do you execute this code? Is it a scripted postfunction?

Eric Collins September 1, 2017

It is a scripted postfunction.

Eric Collins September 1, 2017

@Mathias Edblom

The ideal solution would allow a user to select multiple "Field Sites" (multiselect insight field), create subtasks for each of those selections, then add the Field Site object to the correct subtask. 

 

For example:

User selects field sites: Atlanta, New York, DC

Subtask for Atlanta with field site object "Atlanta" 

Subtask for New York with field site object "New York"

Subtask for DC with field site object "DC"

 

Does that make sense?

0 votes
Eric Collins August 24, 2017

Getting close!!!

I have the script creating subtasks based on a jira multiselect list. I really need to convert that to an Insight multiselect field and copy attributes into the summary field of the newly created subtask.

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.customfields.option.Option

def customFieldManager = ComponentAccessor.customFieldManager

def cf = customFieldManager.getCustomFieldObjectByName("Multiselect Field Sites"// This needs to me changed to a multiselect Insight field

def summariesList = (issue.getCustomFieldValue(cf) as Collection<Option>)*.value

Issue parentIssue = issue

//if the parent issue type name IS NOT Task - do nothing

if (parentIssue.getIssueType().getName() != 'Task')

    return

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def groupManager = ComponentAccessor.getGroupManager()

def issueFactory = ComponentAccessor.getIssueFactory()

def constantManager = ComponentAccessor.getConstantsManager()

def issueManager = ComponentAccessor.getIssueManager()

def subTaskManager = ComponentAccessor.getSubTaskManager()

summariesList.each { subTaskSummary ->

    MutableIssue newSubTask = issueFactory.getIssue()

    newSubTask.setSummary(subTaskSummary + ": " + issue.getSummary())

    newSubTask.setParentObject(parentIssue)

    newSubTask.setProjectObject(parentIssue.getProjectObject())

    newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find {

        it.getName() == "Sub-task"

    }.id)

    

    // Add any other fields you want for the newly created sub task

    Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>

    issueManager.createIssueObject(user, newIssueParams)

    subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)

}
0 votes
Mathias Edblom August 16, 2017

Hi,


Just use the custom field value and create the issues on the projects that you have selected. 


import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;

CustomField cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_xxxxx");
if (issue.getCustomFieldValue(cf) == null) {
    /* No objects selected */
    return;
}

issue.getCustomFieldValue(cf).each{projectObject ->
    def name = projectObject.getName();
   
    /* Create the issue code depending on
       the project name or any attribute
       sepecified on the objects */
}

You can also look into the Insight JAVA API if you need to get more information stored as attributes on the objects.

Look at https://documentation.riada.se

Cheers //Mathias


Eric Collins August 16, 2017

 

I am receiving an error at 

    def name = projectObject.getName();

Eric Collins August 20, 2017

@Mathias Edblom can you take a look at this? What am I missing?

 

error.png

Daniel Yelamos [Adaptavist]
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.
August 21, 2017

Hello Eric

That error could be that the console doesn't know what class projectObject is.

Could you save the script and try to see if it works, even though it gives you that inline error?

Cheers

Dyelamos

0 votes
Mathias Edblom August 16, 2017

Hm, come in twice, same as below...

Eric Collins August 31, 2017

Could you please take a look at the below script?

0 votes
Daniel Yelamos [Adaptavist]
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.
July 25, 2017

Hello Eric.

This could be done through a custom script on the console.

I don't think we offer this kind of functionality. This is some pretty custom stuff. 

If i were you I would load the data through a JSON and send it through a SR Rest Endpoint. That's your safest bet. 

Hope this helps.

Cheers!

Dyelamos

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events