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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

243 views 1 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