Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set Affect/s Version on linked issue

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

2 answers

1 accepted

0 votes
Answer accepted

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
}

Screen Shot 2021-01-12 at 1.34.10 PM.png

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.

Thanks Peter, I noticed another issue even in the code I posted here. Let me poke around some more and check back.

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

 

Screen Shot 2021-01-13 at 10.51.17 AM.png 

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.

It is a Version Picker Single custom field.

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"
}

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.

0 votes
Hana Kučerová Community Leader Jan 12, 2021

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...

Sorry, that was a bad copy of my code, I was trying with and without the S, forgot to add back.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

419 views 13 14
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you