Getting null pointer exception while setting a custom field in groovy script


I am trying to write this simple script that sets the value of a custom field depending on a value of a different custom field

This is the code

import com.atlassian.jira.issue.IssueManager

import com.atlassian.jira.ComponentManager

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.customfields.CustomFieldType

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.project.Project

import com.atlassian.jira.project.ProjectManager

import com.atlassian.jira.issue.issuetype.IssueType

import com.atlassian.jira.issue.IssueImpl

IssueManager issueManager = ComponentManager.getInstance().getIssueManager();

CustomFieldManager cfManager = ComponentManager.getInstance().getCustomFieldManager();

ProjectManager projectManager = ComponentManager.getInstance().getProjectManager();

MutableIssue myissue = issueManager.getIssueObject("POA-6");

CustomField cfAPType = cfManager.getCustomFieldObjectByName("AP type");

CustomField cfPOType = cfManager.getCustomFieldObjectByName("PO type");

CustomField cfProposedDeveloper = cfManager.getCustomFieldObjectByName("Proposed Developer");

def currentissuetype=myissue.getIssueType()


def currentAPType=myissue.getCustomFieldValue(cfAPType)

def currentPOType=myissue.getCustomFieldValue(cfPOType)

def currentdev=myissue.getCustomFieldValue(cfProposedDeveloper)

def developer="pink blue"

if (currentissuetypenm == "Zaratec")




Any idea why I am getting a null pointer exception.

javax.script.ScriptException: java.lang.NullPointerException


2 answers


How do you try to run that script?

And at which line do you get the NullPointerException?



Hi Shamhoon,

if i got it, you want to set the value of custom field according the issue type. If that's right, code should be something like:

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.comments.CommentManager;

// gets a reference to the IssueManager and CustomFieldManager manager classes
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();

//Get the custom field you want to update by id

CustomField customField_toupdate = customFieldManager.getCustomFieldObject( cf_id );

//issue type condition

if (issue.getIssueTypeObject().getName() == "issue_type_name"){

def val_test = "enter_here_the_desired_value"

issue.setCustomFieldValue(customField_toupdate, val_test)

Test it first.

If you use script in create transition place your scripted function in top of list. Add also the store issue function.

Hope that helps,


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


203 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you