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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Issue when converting DocumentIssueImpl in MutableIssue on Scriptrunner


I try to bulk update the description and a custom field of a list of issues that I find with a JQL search. 

here my code : 

import com.atlassian.jira.user.util.UserUtil;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.issue.index.IssueIndexingService;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.label.LabelManager;
import com.atlassian.jira.issue.fields.NavigableField
import com.atlassian.jira.issue.fields.FieldManager;
import com.atlassian.jira.issue.RendererManager;

def sourceFieldId1 = 11202;
def sourceField1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(sourceFieldId1)

String jql = 'key = TTD-1';
boolean doSearch = true;

//user to run the searches as
def username = "XXXXX";

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

UserUtil userUtil = ComponentAccessor.getUserUtil()
IssueManager issueManager = ComponentAccessor.getIssueManager()

SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
def user = userUtil.getUserObject(username)

//Creation of the issue list
ArrayList<Issue> issues = new ArrayList<>();
if(doSearch) {
SearchService.ParseResult parseResult = searchService.parseQuery(currentUser, jql)
if (parseResult.isValid()) {
def searchResult =, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())

else {
//Nothing for now

long start = System.currentTimeMillis();

for(Issue issue : issues){

MutableIssue mi = (MutableIssue) issue;

def cFieldValue1 = sourceField1.getValue(issue)
def cFieldValue2 = issue.getDescription()

String label1 = cFieldValue1
String label2 = cFieldValue2

String label1C
String label2C

label1C = label1.replaceAll("<a>","_")
label2C = label2.replaceAll("<a>","_")

sourceField1.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sourceField1), label1C), new DefaultIssueChangeHolder())


def end = System.currentTimeMillis();
long genTime = end-start;
String outString = "Set Values for "+issues.size()+" issues.";
outString+=" in "+ genTime +"ms";
return outString;

I know it can be optimized but I first have a problem to solve...

If I don't use mutableIssue and that I try to update my issue with this method : 

issue.description = "example"

I have the following error message : 

"groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: description for class: com.atlassian.jira.issue.DocumentIssueImpl"

So I used the mutable issue as you can see in my code, but now I have this error message : 

"org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'DocumentIssueImpl[issueKey=TTD-1]' with class 'com.atlassian.jira.issue.DocumentIssueImpl' to class 'com.atlassian.jira.issue.MutableIssue' at"


Do you have an Idea ?


Thanks in advance.

Best regards,




1 answer

1 accepted

0 votes
Answer accepted

You could try IssueManager to get the MutableIssue:

IssueManager issueManager = ComponentAccessor.getIssueManager()

MutableIssue mutableIssue = issueManager.getIssueObject(


documentIssueImpl in your code would be "issue" from for (Issue issue : issues), so .getIssueObject(; I'd definitely change that because searchresults give DocumentIssueImpl class, at least to me on first look this looks a little confusing what class we're really looking at :)


Thanks for your reply, it works :) 

For information I also added lines to force reindex the ticket.

issueManager.updateIssue(currentUser, mi, EventDispatchOption.DO_NOT_DISPATCH, false) Boolean wasIndexing = ImportUtils.isIndexIssues()IssueIndexingService indexing = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class)indexing.reIndex(mi)ImportUtils.setIndexIssues(wasIndexing)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

4,401 views 12 6
Join discussion

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