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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

854 views 3 12
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