Script working in console but executing and failing when implemented in post function


My script working fine when tested on console but when implemented as post fuction script it failing for one of its case

Script functionality : To copy custome field value from parent to child issue on creation 

Script failure case: when creating an epic which has no parent it give null pointer exception though i have if condition to check that still its trying to access custom field 


if ( ( != 'Epic') && issue != null) { def customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField epiclink = customFieldManager.getCustomFieldObjectByName("Epic Link"); def epic = issue.getCustomFieldValue(epiclink); if (epic != null) { Issue issue1 = ComponentAccessor.getIssueManager().getIssueByKeyIgnoreCase("$epic"); CustomField costcollector = customFieldManager.getCustomFieldObjectByName("Cost Collector"); def cost = issue1.getCustomFieldValue(costcollector); if (cost != null) { issue.setCustomFieldValue(costcollector, cost) } } }



2017-07-18 08:26:08,010 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-07-18 08:26:08,012 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script>
java.lang.NullPointerException: Cannot invoke method getCustomFieldValue() on null object

3 answers

This widget could not be displayed.

Can someone have solution to this problem

This widget could not be displayed.

Check for Epic with if(issue.getIssueType().getName() == "Epic")

Worked for me fine.

Well dont know why it not working in console it working all well but when implemented in post fuction its give error but only in the case of epic creation as epic does not have any parent epic but when we create work package or task  it works just fine

Maybe on wrong position in postfunction?

When i upgraded to Jira 7 i had to move my create-postfunction scripts that do something with issue fields from second position (behind "Creates the issue originally") to the first position (before "Creates ..").

Maybe try some position changes.


Edit: For me the check for issuetype is working in create postfunction when script is on first position

This widget could not be displayed.

Your error message implies that the custom field you're reading is not valid for the issue type you are running the script against.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

564 views 25 15
Join discussion

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