Now that I have gotten my code to work without error, my last issue I am seeing is that when a copy the version value from a single version picker custom field to a linked issue's Affect/s Version field, I show that the value should have been set, but unfortunately I am not seeing it persist.
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkType
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.fields.IssueLinksSystemField
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.comments.CommentManager //testing only
import com.atlassian.jira.user.ApplicationUser //testing only
import com.atlassian.jira.project.version.Version
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser //testing only
try
{
def issue = event.issue as MutableIssue
// define issuetype we will look for the even on
def isAnEscalation = issue.getIssueType()?.name == "Escalation";
// Is this an Escalation issuetype? If not, return
if (!isAnEscalation)
{
return;
}
// Defining links
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
// Defining Product Version and Affect(s) Version
def productVersionCf = customFieldManager.getCustomFieldObject(11622) //Product Version
def productVersionValue = issue.getCustomFieldValue(productVersionCf) //as Version
if (isAnEscalation) //is this an escalation issuetype?
{
List<String> linkTypes = ["Root Cause", "Fixes"] //The list of Link Type you want this script to work on
def linkedIssues = ComponentAccessor.issueLinkManager
.getInwardLinks(issue.id)
.findAll { it.issueLinkType.name in linkTypes
}
linkedIssues.each {
def linkedIssue = it.sourceObject as MutableIssue
log.info "Attempting to set the affectedversion field on $linkedIssue.key to $productVersionValue which is an object of type ${productVersionValue.getClass()}"
linkedIssue.setAffectedVersions([productVersionValue]) //set affected version/s
log.info "$linkedIssue.key affectedVersion is now: $linkedIssue.affectedVersions"
log.info "Attempting to update $linkedIssue.key after setting version"
def IssueManager issueManager = ComponentAccessor.getIssueManager()
// issueManager.updateIssue(currentUser,issue,EventDispatchOption.DO_NOT_DISPATCH, false)
issueManager.updateIssue(currentUser,issue,EventDispatchOption.ISSUE_UPDATED,false)
log.info "$linkedIssue.key update complete"
}
}}
catch(Exception ex)
{
log.info("Error Message, Listener - ES_Version_Copy - Exception:"+ex.getStackTrace());
// log.info("Stack Trace :"+ex.getStackTrace());
}
catch(Throwable ex)
{
log.info("Error Message, Listener - ES_Version_Copy - Throwable:"+ex.getStackTrace());
// log.info("Stack Trace :"+ex.getStackTrace());
}
catch(SocketTimeoutException ex)
{
log.info("Error Message, Listener - ES_Version_Copy - socket timeout exception:"+ex.getStackTrace());
// log.info("Stack Trace :"+ex.getMessage());
}
From looking at my info.log outputs things look to have run successfully.
2021-01-19 14:23:24,580 INFO [runner.ScriptBindingsManager]: Attempting to set the affectedversion field on XXXX-177104 to [5.3.1] which is an object of type class java.util.ArrayList
2021-01-19 14:23:24,581 INFO [runner.ScriptBindingsManager]: XXXX-177104 affectedVersion is now: [[5.3.1]]
2021-01-19 14:23:24,581 INFO [runner.ScriptBindingsManager]: Attempting to update XXXX-177104 after setting version
2021-01-19 14:23:24,581 INFO [runner.ScriptBindingsManager]: XXXX-177104 update complete
Is there something I am missing here as to why things look to have gone perfectly fine, but the value does not persist in the Affect/s Version field of the linked issue? I verified this is not a permissions issue as I am the user shown in the logs and can manually update the field myself on the linked issue.