I have a behavior that enters a bug template into the description field of the issue when it is of type "Bug". However, I want to avoid having people lose information if they go back and change the issue type to Bug after entering information.
STR Example:
I'm checking for a previously filled in form field (using getValue) but the value is returning null always. Is there a different method I should be using?
Code:
import com.onresolve.jira.groovy.user.FieldBehaviours import static com.atlassian.jira.issue.IssueFieldConstants.* import groovy.transform.BaseScript @BaseScript FieldBehaviours fieldBehaviours if (getActionName() != "Create") { return // not the initial action, so don't set default values } def templateValue = """*Device / OS:* *Test Account:* *Precondition:* *Steps to Reproduce:* # # # *Expected Result:* *Observed Result:* *Reproducibility:*""" def descriptionField = getFieldById(DESCRIPTION) def previousValue = (descriptionField.getValue() as String)?.trim(); if(previousValue == null || previousValue?.equals(templateValue)) { previousValue = ""; } else if(previousValue) { previousValue += "\n\n"; } descriptionField.setFormValue(previousValue + templateValue)
You can't do this as an initialiser, because currently the form contents are not available in initialisers. Therefore you need to attach it to a field as in Jonny's example. There you can check whether the value is currently empty.
You can also use getUnderlyingIssue(), which will return null if this is the Create action (better than checking the action by name).
I've switched over to this, but it looks like modifying the field this way turns off inline editing. Even changing the behavior script to add
descriptionField.allowInlineEdit = true
Doesn't seem to fix the issue. Is there something I'm missing to keep inline editing enabled as a result of this behavior?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's deliberate. ScriptRunner automatically disables inline editing for fields that are marked as part of behaviours. The reason for this is that a behaviour can be complex enough that inline editing becomes unhelpful, even harmful in many use cases. Since inline editing can't make dependent fields editable, there's no way to cover one of the most common use cases for behaviours.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure, but is there any way to override that behavior? In this case the behaviour is not complex enough to warrent disabling inline field editing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There's not a great solution for this problem. I'm not sure why allowInlineEdit = true is not working.
The problem is that the current form contents are not available in an initialiser, the rationale being that you can get these values from the issue in the database. The problem comes when you switch project or issue type, then the initialiser runs again.
I've created an issue for this: https://productsupport.adaptavist.com/browse/SRJIRA-2027
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There's a related bug for allowInlineEdit that is still in "TODO".
https://productsupport.adaptavist.com/browse/SRJIRA-292
In experiments on a test server, allowInlineEdit works about half the time, but I've never had it work on our actual instance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Initializers run when you switch types, the field validators run every time you switch on / off fields. I'd love for the initializer to know what's in the form after it's been loaded but it appears that's not a thing it can do.
I've had to modify the code slightly to work bound to the description field instead (to prevent issues when switching back and forth between different issue types)
import com.onresolve.jira.groovy.user.FieldBehaviours import static com.atlassian.jira.issue.IssueFieldConstants.* import groovy.transform.BaseScript @BaseScript FieldBehaviours fieldBehaviours if (getActionName() != "Create") { return // not the initial action, so don't set default values } def templateValue = """*Device / OS:* *Test Account:* *Precondition:* *Steps to Reproduce:* # # # *Expected Result:* *Observed Result:* *Reproducibility:*""" def descriptionField = getFieldById(DESCRIPTION) def previousValue = (descriptionField.getValue() as String)?.trim(); if(previousValue?.length() <= 0) { descriptionField.setFormValue(templateValue) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, attaching the behaviour to the description field will seemed to make your script work, so... probably that's better than an initializer, for your use case? The initializers only run once when the form is loaded.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Odd. That script actually works for me. What version of JIRA and ScriptRunner are you using?
Here's some quick screenshots of how I configured it. Maybe you need to adjust the mapping?
Screen Shot 2016-09-07 at 1.33.10 PM.pngScreen Shot 2016-09-07 at 1.33.17 PM.png
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.