Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×I need to add fix version for the linked issue. But script I've wrote doesn't take effect.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.link.IssueLink import com.atlassian.jira.user.ApplicationUser String processBlockingIssue(MutableIssue origin, Issue issue) { ApplicationUser user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser() issue.fixVersions.addAll(origin.fixVersions) ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_ASSIGNED, true); return origin.fixVersions.join(","); } MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("LIC-197"); MutableIssue myIssue = issue List<IssueLink> links = ComponentAccessor.getIssueLinkManager().getOutwardLinks(myIssue.id) String str = ""; for (IssueLink link : links) { if ("Blocks".equalsIgnoreCase(link.issueLinkType.name)) { str += processBlockingIssue(myIssue, link.destinationObject) } } str;
I get result "0,5" after calling script in script console. That is only version that alredy assign to issue LIC-197. I have issue LIC-196 that blocks by LIC-197.
Issue LIC-196 and fixVersion define correctly. But issue is not updated.
when updating most native fields like fixVersion I always have to do a
issue.store();
and based on the way you are creating your issue, you should also do a reindex at the end of the post function.
Change processBlockingIssue to this
ApplicationUser user = ComponentAccessor.jiraAuthenticationContext.user issue.setFixVersions(origin.getFixVersions()) issue.store();
But it doesn't work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
start putting in some log statements and make sure you are updating what you think you are updating. That your loop actually finding LIC-196 and trying to update it with what ever is in LIC-197 (your Origin).
you could also try casing issue as a MutableIssue. and see if that helps.
As I also mentioned you probably need to reindex it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
script was change to
String processBlockingIssue(MutableIssue origin, MutableIssue issue) { Project project = issue.getProjectObject() Version version = ComponentAccessor.getVersionManager().getVersion(project.getId(), "0.5") def res = "\n Updating issue ${issue}." issue.setFixVersions([version]) issue.description = "changed description" issue.store(); boolean wasIndexing = ImportUtils.isIndexIssues(); ImportUtils.setIndexIssues(true); ComponentAccessor.getIssueIndexManager().reIndex(ComponentAccessor.getIssueManager().getIssueObject(issue.getId())); ImportUtils.setIndexIssues(wasIndexing); res += " Set fix version = [" + issue.fixVersions.join(",") +"]. Saved fix versions = ["+ ComponentAccessor.getIssueManager().getIssueObject(issue.getId()).fixVersions.join(",")+"]" return res; }
After execution in console I have result
pdating issue LIC-196. Set fix version = [0.5]. Saved fix versions = []
But description have been changed what is wrong? May be there is other way to save fixVersions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes there is another way.. There are actually a couple of ways. here is some code I use that works... and BTW, you version 0.5 .. it wouldn't happen to be archived would it?
Also looking at some older code, this should have worked for you.
issueManager.updateIssue(userManager.getUserObject('automation'), issue, EventDispatchOption.DO_NOT_DISPATCH, false);
public void setFixVersions4Issue(Long versionID, MutableIssue issue) { IssueChangeHolder changeHolder = new DefaultIssueChangeHolder(); OrderableField field = ComponentAccessor.getFieldManager().getOrderableField("fixVersions"); Collection<Version> Col_Versions = issue.getFixVersions(); Collection<Version> archVers = VersionUnArchive(Col_Versions); Col_Versions.clear(); if (versionID == null) { issue.setFixVersions(null); } else { Version tempVersion = versionManager.getVersion(versionID); Col_Versions.add(tempVersion); issue.setFixVersions(Col_Versions); } field.updateValue(null, issue, new ModifiedValue(issue.getFixVersions(), Col_Versions), changeHolder); VersionReArchive(archVers); indexManager.reIndex(issue); } public Collection<Version> VersionUnArchive(Collection<Version> inVersions) { Logger thislog = Logger.getLogger("VersionUnArchive"); thislog.setLevel(Level.ERROR); thislog.debug("Starting VersionArchive"); Collection<Version> archVers = new ArrayList<>(); for (Version version : inVersions) { if (version.isArchived()) { archVers.add(version); version.setArchived(false); } } return archVers; } public void VersionReArchive(Collection<Version> inVersions) { Logger thislog = Logger.getLogger("VersionReArchive"); thislog.setLevel(Level.ERROR); thislog.debug("Starting VersionArchive"); for (Version version : inVersions) { version.setArchived(true); } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have found error. All I need it's to change one line.
ComponentAccessor.getIssueManager().updateIssue(user.directoryUser, (MutableIssue) issue, EventDispatchOption.ISSUE_UPDATED, Boolean.FALSE)
EventDispatchOption.ISSUE_ASSIGNED must be replaced by EventDispatchOption.ISSUE_UPDATED
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.