Updating multi-Sslect checkbox value from one issue to another issue via custom script

We have one multi select checkbox custom field called Impacted Application here suppose  I have selected 3 values and these three values should be carried and added to another issue with this custom field name.

 

for this,  we have written some code as below

{code}

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.component.ComponentAccessor;
import com.atlassian.jira.config.SubTaskManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.link.IssueLinkType;
import com.atlassian.jira.issue.link.IssueLinkTypeManager;

Issue parentIssue = issue;
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
IssueService issueService = ComponentAccessor.getIssueService();
CustomField brdTitle = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(new Long(10249));
String brdTitleValue = parentIssue.getCustomFieldValue(brdTitle);

CustomField impactedApplication = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(new Long(10242));
String impactedApplicationValue = parentIssue.getCustomFieldValue(impactedApplication);

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setIssueTypeId("10000");
issueInputParameters.setProjectId(parentIssue.getProjectId());
issueInputParameters.setAssigneeId(parentIssue.getAssigneeId());
issueInputParameters.setReporterId(parentIssue.getReporterId());
//issueInputParameters.setDescription(parentIssue.getDescription());
issueInputParameters.setSummary(parentIssue.getSummary());
issueInputParameters.addCustomFieldValue(new Long(10002), "Test");
issueInputParameters.addCustomFieldValue(new Long(10508), brdTitleValue);

if(impactedApplicationValue!=null)
{
Options options = ComponentAccessor.getOptionsManager().getOptions(impactedApplication.getConfigurationSchemes().listIterator().next().getOneAndOnlyConfig());
def optionToSelect = options.find { it.value == "PPM" };
issueInputParameters.addCustomFieldValue(impactedApplication.getId(), optionToSelect.getOptionId().toString());
}

CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInputParameters);

if (createValidationResult.isValid())
{
IssueResult createResult = issueService.create(user, createValidationResult);
if (createResult.isValid())
{
Issue subTask = createResult.getIssue();
IssueLinkTypeManager issueLinkTypeManager = (IssueLinkTypeManager)ComponentAccessor.getComponent(IssueLinkTypeManager.class);
IssueLinkType linkType = issueLinkTypeManager.getIssueLinkType(new Long(10303));
ComponentAccessor.getIssueLinkManager().createIssueLink(subTask.getId(),parentIssue.getId(), linkType.getId(), null, user);
}
else
{
// System.out.println("Invalid createResult");
}
}

{code}

 

0 answers

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,802 views 11 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot