Hi all,
I am trying to use a Scripted Field to return a list of various responses, based on particular field values. For example, if the field "App1 Action Required" has a value of "Yes," I want the phrase "App1 Admin" to be added to a list that returns as the scripted field value. This is the inline script, which is currently returning a java.lang.NullPointerException... help?!
//resources
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
def customFieldMgr = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
//define result
def result = []
//add the specific phrase "App1 Admin" to the list of results if the value of c.f. "App1 Action Required" equals "Yes"
def actionApp1 = customFieldMgr.getCustomFieldObjectByName("App1 Action Required")
def valueApp1 = issue.getCustomFieldValue(actionAptos).toString()
if (valueApp1 == "Yes") {
def printApp1 = "App1 Admin"
result.add(printApp1)
}
//add the specific phrase "App2 Admin" to the list of results if the value of c.f. "App2 Action Required" equals "Yes"
def actionApp2 = customFieldMgr.getCustomFieldObjectByName("App2 Action Required")
def valueApp2 = issue.getCustomFieldValue(actionADP).toString()
if (valueApp2 == "Yes") {
def printApp2 = "App2 Admin"
result.add(printApp2)
}
//print full list of results
result
Disclaimer: I am not very good at this..
You have
def valueApp1 = issue.getCustomFieldValue(actionAptos).toString()
But actionAptos is not defined anywhere in your code? You should be passing in the custom field object that you got the line before ("actionApp1"):
//resources
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
def customFieldMgr = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
//define result
def result = []
//add the specific phrase "App1 Admin" to the list of results if the value of c.f. "App1 Action Required" equals "Yes"
def actionApp1 = customFieldMgr.getCustomFieldObjectByName("App1 Action Required")
def valueApp1 = issue.getCustomFieldValue(actionApp1).toString()
if (valueApp1 == "Yes") {
def printApp1 = "App1 Admin"
result.add(printApp1)
}
//add the specific phrase "App2 Admin" to the list of results if the value of c.f. "App2 Action Required" equals "Yes"
def actionApp2 = customFieldMgr.getCustomFieldObjectByName("App2 Action Required")
def valueApp2 = issue.getCustomFieldValue(actionApp2).toString()
if (valueApp2 == "Yes") {
def printApp2 = "App2 Admin"
result.add(printApp2)
}
//print full list of results
result
I forgot to change that one. (I changed the names of the actual "apps" we are using in our instance.) Good catch! However, even when aligning my verbiage as you describe, I am still drawing a java.lang.NullPointerException.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Clayton,
Thanks for the information. The fields you are using are checkbox fields, right? In that case, getting the custom field value of a checkbox field will return an array of values, e.g. if someone selects 'Yes', the value returned will be: [Yes]. You should perhaps try calling the contains() method on the checkbox value instead.
//resources
import com.atlassian.jira.component.ComponentAccessor
def customFieldMgr = ComponentAccessor.getCustomFieldManager()
//define result
def result = []
//add the specific phrase "App1 Admin" to the list of results if the value of c.f. "App1 Action Required" equals "Yes"
def actionApp1 = customFieldMgr.getCustomFieldObjectByName("App1 Action Required")
def valueApp1 = issue.getCustomFieldValue(actionApp1) as String
if (valueApp1.contains("Yes")) {
def printApp1 = "App1 Admin"
result.add(printApp1)
}
//add the specific phrase "App2 Admin" to the list of results if the value of c.f. "App2 Action Required" equals "Yes"
def actionApp2 = customFieldMgr.getCustomFieldObjectByName("App2 Action Required")
def valueApp2 = issue.getCustomFieldValue(actionApp2).toString()
if (valueApp2.contains("Yes")) {
def printApp2 = "App2 Admin"
result.add(printApp2)
}
//print full list of results
result
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 response, Josh.. I actually got it working using the script below. Thank you for your help!
//preparatory
import com.atlassian.jira.component.ComponentAccessor
def customFieldMgr = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def result = []
//build outputs
def app1value = customFieldMgr.getCustomFieldObjectByName("Action Required App1")
def app1print = "App1 Admin"
if (app1value) {
def app1opt = issue.getCustomFieldValue(app1value)
if (app1opt && app1opt.getValue() == "Yes") {
result.add(app1print)}};
def app2value = customFieldMgr.getCustomFieldObjectByName("Action Required App2")
def app2print = "App2 Admin"
if (app2value) {
def app2opt = issue.getCustomFieldValue(app2value)
if (app2opt && app2opt.getValue() == "Yes") {
result.add(app2print)}};
//print output
result
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to hear it is working, Clayton. Apologies that I could not get back to you sooner.
Thanks for using ScriptRunner!
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.