Issues with subtask creation through workflow transition

Hi,

We have a requirement to create a sub-task through workflow transition. While creating sub-task few custom filed values from parent issue should be inherited to sub-task. We have created a separate custom field for the sub-task issue. For example - if we have a custom field called Status, the in sub-task we have field  called Ticket Status of same type. We copy the value of Status to Ticket Status field through script listener while creating parent issues. This approach works fine for all other fields except for multi select field. This is the code we are using to copy values from multi select field to multi select field.

void workflowEvent(IssueEvent event) {
	Issue issue = event.getIssue()
	// some code 
	copyMultiSelectToMultiSelect("Status", "Ticket Status", issue)
}
 
void copyMultiSelectToMultiSelect(String sourceCustomFieldName, String destCustomFieldName, Issue issue) {
    CustomField sourceCF = customFieldManager.getCustomFieldObjectByName(sourceCustomFieldName)
    CustomField destinationCF = customFieldManager.getCustomFieldObjectByName(destCustomFieldName)

    FieldLayoutManager fieldLayoutManager = ComponentAccessor.getFieldLayoutManager()

    def newValue = issue?.getCustomFieldValue(sourceCF)
    List<Option> converted = new ArrayList<Option>()
    for (Option s : newValue) {
        //LOG.info "Option value is : ${s.getValue()}"
        converted.add(s);
    }
    if (newValue != null) {
        FieldLayoutItem fieldLayoutItem = fieldLayoutManager.getFieldLayout(issue).getFieldLayoutItem(destinationCF);
        destinationCF.updateValue(fieldLayoutItem, issue, new ModifiedValue(null, converted), new DefaultIssueChangeHolder());
    } else {
        FieldLayoutItem fieldLayoutItem = fieldLayoutManager.getFieldLayout(issue).getFieldLayoutItem(destinationCF);
        destinationCF.updateValue(fieldLayoutItem, issue, new ModifiedValue(null, null), new DefaultIssueChangeHolder());
    }
}

 

Can anybody suggest what we are missing?

Thanks,

Raj

1 answer

Could you consider using the same custom field for parent and subtask?

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
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

86 views 0 5
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