Linked issue persistence issue

I'm trying to create a post function script that transtions linked issues on transition of parent issue (trying to setup epic -> story for kanban board so when I prioritze epic linked stories are prioritized too).

All was going well but I'm hitting an issue. There's a contraint on the story workflow that two custom fields must be populated - team (multi select) and fix release.

I have the following code:

issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->

        if (issueLink.destinationObject.getStatusObject().getName() == toBePrioritized){
            // Transition
            log.debug("updating linked issue status from "+issueLink.destinationObject.getStatusObject().getName()+" to "+priorityReviewed);
            workflowTransitionUtil.setIssue(issueLink.getDestinationObject());
            workflowTransitionUtil.setUsername(currentUser);
            workflowTransitionUtil.setAction(301);
// validate and transition issue
            workflowTransitionUtil.validate();
            workflowTransitionUtil.progress();
            log.debug("successful transtion of "+issueLink.destinationObject.getKey());

        }
        
        if (issueLink.destinationObject.getStatusObject().getName() == priorityReviewed){
            // Transition
            workflowTransitionUtil.setIssue(issueLink.getDestinationObject());
            workflowTransitionUtil.setUsername(currentUser);
            workflowTransitionUtil.setAction(141);
            
            //write targetRelease to custom field
            def linkedTargetReleaseField = customFieldManager.getCustomFieldObjects(issueLink.destinationObject).find {it.name == targetReleaseString}
            Project project = issueLink.destinationObject.getProjectObject();
            Version version = componentManager.getVersionManager().getVersion(project.getId(), targetReleaseFieldValue);
            linkedTargetReleaseField.updateValue(null, issueLink.destinationObject, new ModifiedValue(issueLink.destinationObject.getCustomFieldValue(linkedTargetReleaseField), version),new DefaultIssueChangeHolder());

            //write team to custom field
            def linkedTeamField = customFieldManager.getCustomFieldObjects(issueLink.destinationObject).find {teamString}
            OptionsManager optionsManager = ComponentAccessor.getOptionsManager();
            Option teamOption = optionsManager.getOptions(linkedTeamField.getRelevantConfig(issueLink.destinationObject)).getOptionForValue(teamValue, null);
            issueLink.destinationObject.setCustomFieldValue(linkedTeamField,[teamOption])

            // validate and transition issue
            workflowTransitionUtil.validate();
            workflowTransitionUtil.progress();
            log.debug("successful transtion of "+issueLink.destinationObject.getKey()+" to Ready For Development");

        }

however I'm getting an error:

[Error list: [[Team must be defined]]]

This suggests the linked issue (or issueLink.destinationObject) is not getting updated/persisted correctly. What am I doing wrong?
(P.s I'm aware I'm likely making other mistakes too - this is the first time I've tried this....)

1 answer

1 accepted

I was parsing out values from the parent by doing:

Object teamVal = teamField.getCustomFieldType().getValueFromIssue(teamField, issue);

String teamValue = (String)teamVal == null ? "" : teamVal.toString();

It turns out this produced [team A] - the square brackets caused the mappings to fail. Fixed by doing:

Object teamVal = teamField.getCustomFieldType().getValueFromIssue(teamField, issue);

String teamValue = (String)teamVal == null ? "" : teamVal.toString().replaceAll("\\[", "").replaceAll("\\]","");

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
Posted Thursday in Off-topic

Friday Fun: Magic Eyes

...staring into the background. Once the image pops out in 3D, you can look around the picture and enjoy. If you will see if you are a true illusion master! :) You did it? :) Wow! Awesome! As a bonus...

445 views 83 11
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