I am trying to make a custom field (Reason for being Critical/Blocker) to be required when the priority is Blocker or Critical.
I am having trouble getting my code to work. I am getting the error [issue] undeclared and I can't seem to get rid of it.
Here's my current behaviour script:
import com.atlassian.jira.issue.IssueConstantImpl
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue
@BaseScript FieldBehaviours fieldBehaviours
def reasonField = getFieldByName("Reason for being Critical/Blocker")
Issue issue = issue
def Priority = issue.getPriority().getName()
if (Priority == 'Blocker' || Priority == 'Critical') {
reasonField.setRequired(true)
} else {
reasonField.setRequired(false)
}
Any ideas??!
Hmm, I think you are mixing things.
The construction "@Basescript ...." is for REST Endpoints, you are building a behavoiur here ?
Also "issue" is is not defined in the context of behaviours, you should get the contents of the fields by getFieldById or getFieldByName, or access the issue properties by issuecontext.
See the (excellent) examples in the doc !!! https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours.html
I've tried removing the @BaseScripts and still haven't been able to get the priority status back.
def priority = getFieldById("Priority")
def status = priority.getValue()
When going to the logs I see status is returning as null.
I even tried:
String status = priority.getValue() as String
This still returns null.
The only way I can get any data back is when I use :
componentAccessor.getConstantsManger.getPriorities()
priorities.getAt(INDEX).getName() is the only way I can get a value but it does not get the selected value since it is index specific
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
"Priority" is not the correct "id" for the field Priority, I think it is "priority" (system field id's always start with lowercase!).
so you should write
def priorityField = getFieldById("priority")
or use
def priorityField = getFieldByName("Priority")
For more info about how finding the id of a system field, see https://community.atlassian.com/t5/Jira-questions/how-to-find-system-field-id/qaq-p/281440
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you mean getFieldById("priority") returns a null object ???
or the subsequent getValue() returns null ??
I just tried the getFieldById("priority") and it returns me the correct (system) Priority field.
Also getFieldByName("Priority") works...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I see I use in my behaviour scripts everywhere getFormValue() iso getValue() ?
For the priority I use priorityField.getFormValue()?.name to get the priority (as text)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
priorityField.getFormValue()?.name is not an option.
I don't have any additional options for priorityField.getFomValue()
Am I missing a specific import??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The message you get is just a compiler type check warning (the compiler does not know what object type getFormValue() returns. You can ignore it.
I did some more tests, and indeed, it seems impossible to capture the contents of the priority field. In my existing scripts I was just changing the read-only property of the priority field and this works fine.
This is what I found using a priority field with a value filled in:
FormField priorityField = getFieldById("priority")
log.debug (">priority form value=${priorityField.getFormValue()}")
log.debug (">priority value=${priorityField.getValue()}")
log.debug (">priority field=${priorityField}")
In the logs the getValue() and getFormValue() both return null, when logging the priorityfield itself it also shows ...value=null...
But
FormField priorityField = getFieldById("priority")
priorityField.setReadOnly(true)
correctly sets the priority field read only.
So the field is corerctly identified, but access to the field value is broken.
In the browser debugger I found that also the name (id) "priority-field" was used, so I tried
FormField priorityField = getFieldById("priority-field")
log.debug (">priority form value=${priorityField.getFormValue()}")
log.debug (">priority value=${priorityField.getValue()}")
log.debug (">priority field=${priorityField}")
same results : always returns null, while
FormField priorityField = getFieldById("priority-field")
priorityField.setReadOnly(true)
correctly sets the field to read-only.
So I think there is a bug/incompatibility between scriptrunner and jira. I would suggest you to register this at Adaptavist support...
P.S. we are using an older version of Jira (7.4.3), no idea if this is "resolved" in more recent versions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your persistence on this!
We are currently running v8.3.2 and I'm getting the same results (glad it's not just me going crazy!!)
I'll register this at Adaptavist Support and let you know what comes of it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Caled do you have any updates?
Because I have the same problem and need to fix it asap!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Caleb do you have any updates from Adaptavist support , Because I have the same problem
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.