Can I prevent leading (and trailing) whitespace for single line text (e.g. Summary) field?

Martin Baschnegger October 9, 2011

It does happen from time to time that developers enter issues with leading or trailing whitespaces. (We're currently on Jira v 3.11)

This is annoying when processing issue data with custom scripts down the pipeline.

Is it possible to validate issue fields for leading / trailing spaces, or to auto-trim all whitespace from (some) issue fields?

1 answer

1 accepted

2 votes
Answer accepted
Dieter
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.
October 23, 2011

Hi Martin,

I do this kind of post processing actions using the Groovy Script Runner Plugin. You can get it from here: https://studio.plugins.atlassian.com/wiki/display/GRV/Script+Runner

You have to follow these steps:

- Install Groovy Script Runner Plugin

- Create a Groovy script file with this content

String trim(String s) {
if (s == null) return null
return s.trim()
}
issue.setSummary(trim(issue.getSummary()))
   issue.setDescription(trim(issue.getDescription()))

- Add a "Groovy Script Post-Function" _before_ the post function "Create the issue originally" in the transition "Create". (This is the transition that leads in state "Open"). You must enter the full path to your Groovy Script file.

Cheers,

Dieter

Martin Baschnegger November 6, 2011

Thanks. My, would it be nice if there was something built-in, and I'd not have to manually script yet another thing :-) (Might I ask what Jira Version you're on ... Anything new on this front in JIRA 4 or 5 ?)

JamieA
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.
November 6, 2011

Think that should be: issue.getSummary().trim() etc

Dieter
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.
November 6, 2011

yes, of course. i had my own method trim to also handle the case issue.getSummary() == null, This method is missing here

JamieA
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.
November 6, 2011

Best way to handle that is issue.setSummary(issue.summary?.trim() ?: "")

Which makes me think that you need to be careful with even the most simplest scripts, and test for null values and so on.

Suggest an answer

Log in or Sign up to answer