Use multiselct to create issues in multiple projects

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

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

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

Could you please take a look at the below script?

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


 

I am receiving an error at 

    def name = projectObject.getName();

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

 

error.png

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

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)

}

please see above @Mathias Edblom.

Hi Eric,

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

It is a scripted postfunction.

@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?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,148 views 0 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you