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 Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,364 views 15 19
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