Sharing this with the Jira Data Center admins who use ScriptRunner HAPI.
I was using HAPI to update some issue fields and it threw an error when it hit an issue with a carriage return in the Summary field, even though I wasn't updating that field.
My script looked something like this:
Issues.search("Project = ABC").each { issue ->
issue.update {
issue.setFieldA("New Value")
}
}
How did that carriage return get into the Summary field? I had imported 200K issues from another system during a migration and it didn't occur to me to check the Summary field for carriage returns before I did the import. The import worked fine and imported the carriage returns into the Summary field without complaint, even though they don't show up when you look at the issue in Jira.
Since I didn't know which issue caused the problem and there may have been many of them (in fact there were about 20K issues with this problem), I needed to check them all.
My solution was to use the following script:
import java.util.stream.Collectors
def issues = Issues.search('project = ABC')
.stream()
.filter { issue -> issue.getSummary().contains("\n")}
.collect(Collectors.toList())
.each { issue ->
issue.update {
setSummary(issue.getSummary().replace("\n", " "))
}
}
I worried that even with the filter, the resulting data would overwhelm the server memory. In my case, it was able to handle it. If you know how to process the filter results without having to collect them into a list first (i.e., run the issue.update() function on each issue as it comes out of the filter, let me know if the comments.
Derek Fields _RightStar_
Atlassian Practice Manager
RightStar
80 accepted answers
2 comments