Trying to set affectedVersions to existing version

Originally asked by MaxH on 24 July 2023 (original question)


Hi Community,

I am working on an internal connection on Jira on-prem.

AffectsVersion(s) is a mandatory field in one of the projects (by validator in workflow).

I want to set it to a default version “Default_Version”.

Somehow this code does not work:

issue.projectKey = "XY"
issue.affectedVersions += nodeHelper.getVersion("Default_Version", nodeHelper.getProject(issue.projectKey))

I receive an error message like: Can’t set version object to java.util (unfortunately I can’t access the tool right now for the correct message).

Interesting is that

affectedVersion = nodeHelper.getVersion("Default_Version", nodeHelper.getProject(issue.projectKey))
debug.error(affectedVersion.name)

returns “Default_Version” correctly.

Any idea? Does Exalate interfere with the validator here? Or is it just some logical mistake / typo?

Best regards,

Max


Answer by Syed Majid Hassan on 13 August 2023

Try this please:

    issue.affectedVersions = null
    if (replica.affectedVersions.size() == 0){
      issue.affectedVersions = [nodeHelper.getVersion("Default_Version", project)]
    }
    else{
        replica.affectedVersions.each {
            v -> 
            if (nodeHelper.getVersion(v.name, project))
                issue.affectedVersions += nodeHelper.getVersion(v.name, project)
            else
                issue.affectedVersions += nodeHelper.createVersion(issue, v.name, v.description)
            }
    }  

Let me know how it goes.

Thanks

Majid


Answer by MaxH on 06 September 2023

Thanks for your reply Syed Majid Hassan . I figured it out in the mean time: I overwrote the affectedVersions at a later point in the script -.-


Comments:

Syed Majid Hassan commented on 07 September 2023

Nice.
Glad that you got it working!

Answer by MaxH on 25 July 2023

Current exception thrown:

Exalate has problems while trying to create an issue in this Jira. Details: [InvalidInputException: [Error map: [{versions=Please add a value to the required fields Affects Version/s!}]] [Error list: []]