Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update custom version picker

Rob Schalken April 20, 2018

I want to write a custom field version picker (release_version_int).

But I continuous get the following error:

<Error>

java.lang.ClassCastException: com.atlassian.jira.project.version.VersionImpl cannot be cast to java.util.Collection at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:39) at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:693) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:410) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396) at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source) at Script227.run(Script227.groovy:34)

</Error>

I used the following code

<code>

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.workflow.JiraWorkflow
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.ComponentManager;

// Retrieve issue ID => Only for debugging in console
def issueManager = ComponentAccessor.getIssueManager();
MutableIssue issue = issueManager.getIssueObject("CV-318");

// Get stored version information
def relVersion = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(issue).find {it.name == 'release_version'};
def newVersion = issue.getCustomFieldValue(relVersion);

// Get release_version_int object
def relVersion_int = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(issue).find {it.name == 'release_version_int'};

// get project id
def projectId = issue.getProjectObject().getId();

// Get version
def version = ComponentAccessor.getVersionManager().getVersion(projectId, newVersion);

// Store version in the release_version_int => Required for linking
issue.setCustomFieldValue(relVersion_int, version);
issueChangeHolder = new DefaultIssueChangeHolder();
relVersion_int.updateValue(null, issue, new ModifiedValue("", issue.getCustomFieldValue(relVersion_int)), issueChangeHolder);            
issue.store();              
def newVersion_int = issue.getCustomFieldValue(relVersion_int);

</code>

Any suggestions?

1 answer

1 accepted

1 vote
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 20, 2018

What is line 34 in your script?

Rob Schalken April 20, 2018

The update function:

relVersion_int.updateValue(null, issue, new ModifiedValue("", issue.getCustomFieldValue(relVersion_int)), issueChangeHolder);            

It looks that it is not possible to update an version picker this way.

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 20, 2018

Try to write like this

relVersion_int.updateValue(null, issue, new ModifiedValue("", [issue.getCustomFieldValue(relVersion_int)]), issueChangeHolder);            

Rob Schalken April 20, 2018

This indeed does do the trick. Thanx

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 20, 2018

If my answer hepled you, kindly accept my answer so that other people could find this answer, if they have a similair question

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events