Hello, I am running into issues with attempting to set the Affect/s Version system field on a linked issue with a value from a custom field that is a version field. The issue I am having is that this piece of code gives me an error of Cannot find matching method:
destinationIssue.setAffectedVersion(productVersion)
I have even tried performing the same action on the FixVersions field for a test and the same error in my code. Is there something I am missing here?
Using JIRA DataCenter 8.5
Try:
destinationIssue.setAffectedVersions([productVersion])
Since Affect/s Version allows more than 1 value, you must specify a Collection
Thanks Peter, I tried that and still getting this error.
More of the code if it helps.
// Defining Product Version and Affect(s) Version
def productVersion = customFieldManager.getCustomFieldObject(11622) //Product Version
boolean filterLinkedIssueTypes = true //Set this to false to leave a comment on any Linked Issue Types
List<String> linkedIssueTypes = ["Story", "Bug"] //The list of the Linked Issue Types we want to leave a comment on
boolean filterLinkTypes = true //Set this to false to leave a comment on any Link Types
List<String> linkTypes = ["Root Cause"] //The list of Link Type you want this script to work on
if (isAnEscalation) //is this an escalation issuetype?
{
issueLinkManager.getOutwardLinks(issue.id).each { IssueLink issueLink ->
if (issueLink.issueLinkType.name in linkTypes) //looking at link type used
{
def destinationIssue = issueLink.destinationObject
if (destinationIssue.issueType.name in linkedIssueTypes) //looking at issuetype of linked issue
{
def versionManager = ComponentAccessor.getVersionManager()
def projectManager = ComponentAccessor.getProjectManager()
def project = projectManager.getProjectObjByKey(destinationIssue.projectObject.key)
def versions = destinationIssue.getFixVersions() //grabbing current versions listed on linked issue
if(!versions.contains(productVersion)) //if version in Affect/s Version does not match Product Version then we will continue to set a value
{
destinationIssue.setAffectedVersions([productVersion]) //set value of Affect/s Version from Product Version
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah the full context and screenshot really helps.
As you can see in the error, you are giving the setAffectdVersions a list of "CustomField" object. When you see to provide a Version object
Looking at the line where the ProductVersion is defined:
def productVersion = customFieldManager.getCustomFieldObject(11622) //Product Version
We can see that this is just defining the custom field object.
Perhaps try like this:
def productVersionCf = customFieldManager.getCustomFieldObject(11622) //Product Version
def productVersion = issue.getCustomFieldValue(productVersionCf)
Now, if you need the extract the product version from the linked issues and not the current issue, then you will need put the def productVersion inside the "each" block and use destinationIssue.getCustomFieldValue(productVersionCf).
You may still get a static type checking issue if the code editor doesn't know that List and Collection can be handled as the same at runtime, in that case, the error can be ignored. The real test will be the execution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Peter, I noticed another issue even in the code I posted here. Let me poke around some more and check back.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter, I am back and have made some changes to clean up my code and verified that my code works if I want to leave a comment on a linked issue with the data from the custom field version picker. Sadly, I still am having issues populating Affect Version/s as I want though due to still seeing a static check error. I attempted to test even with the static check error and no such luck. I checked logging and no errors shown as well.
import com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkTypeimport com.atlassian.jira.issue.IssueFieldConstantsimport com.atlassian.jira.issue.link.IssueLinkManagerimport com.atlassian.jira.issue.fields.IssueLinksSystemFieldimport com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.comments.CommentManager //testing onlyimport com.atlassian.jira.user.ApplicationUser //testing only
CommentManager commentMgr = ComponentAccessor.getCommentManager() //testing onlyApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser //testing only
try{
def issue = event.issue as MutableIssue // define issuetype we will look for the even ondef isAnEscalation = issue.getIssueType()?.name == "Escalation"; // Is this an Escalation issuetype? If not, return if (!isAnEscalation) { return; }
// Defining linksdef fieldManager = ComponentAccessor.getFieldManager()def linksSystemField = fieldManager.getField("issuelinks") as IssueLinksSystemFielddef customFieldManager = ComponentAccessor.getCustomFieldManager()def issueLinkManager = ComponentAccessor.getIssueLinkManager()
// Defining Product Version and Affect(s) Versiondef productVersionCf = customFieldManager.getCustomFieldObject(11622) //Product Versiondef productVersionValue = issue.getCustomFieldValue(productVersionCf)def productVersion = productVersionValue.toString()
// def IssueManager issueManager = ComponentAccessor.getIssueManager() //testing onlydef commentManager = ComponentAccessor.getCommentManager()//testing only
if (isAnEscalation) //is this an escalation issuetype? {
def linkedIssues = ComponentAccessor.issueLinkManager .getOutwardLinks(issue.id) .findAll { it.issueLinkType.name.contains('Mitigation')} //&& it.destinationObject.issueType.name == 'Bug' } linkedIssues.each { def linkedIssue = it.destinationObject // commentMgr.create(linkedIssue, currentUser, productVersion, true) //testing only linkedIssue.setAffectedVersions([productVersionValue]) //set affected version/s
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What type of customfield is your Product Version customer field (11622)?
Is that text, Version Picker Single or Version Picker Multiple?
That will make a difference for how to apply the value to the built-in version field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A few things to try
1) add import com.atlassian.jira.project.version.Version
2) add "as Version" when getting the productVersionValue
def productVersionValue = issue.getCustomFieldValue(productVersionCf) as Version
3) add "as MutableIssue when setting the linkedIssue:
def linkedIssue = it.destinationObject as MutableIssue
This makes all the static type error go away in my environment.
For additional debugging, you can try something like this:
linkedIssues.each {
def linkedIssue = it.destinationObject as MutableIssue
log.info "Attempting to se the affected version 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"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Peter that definitely helped and it no longer gives a static error. I can see in the logs it is attempting to now perform the requested actions, but is tossing an exception in doing so. This is progress as I now know it is at least attempting to set the version field Affect Version/s. Let me see if I can debug this some and check back, but you have solved my issue with the static check on setting the value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Casey Hinkle ,
welcome to the Atlassian Community!
I believe the correct method name is: setAffectedVersions (you're missing the last "s")
You would need to provide collection of version objects...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, that was a bad copy of my code, I was trying with and without the S, forgot to add back.
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.