Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

getCustomFieldValue() always returns null in post function, although it works in Script Console

Hi,

I'm running the latest JSD with Scriptrunner 6.7.0, and I have a simple portal like this:

QQ截图20200907210223.png

I'm trying to retrieve the value from a Database Picker field called "Add Roles" in a post function set to trigger when the issue is resolved.

I have the following code, in the post function, to print the value of the field:

def customFieldManager = ComponentAccessor.getCustomFieldManager()


log.debug("Roles: ${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectsByName("Add Roles")[0])}")

 But when the post function runs, it always prints

Roles: null

despite the field is not empty.

 

However, when I try to do the same in Script Console, for example,

// Use the same issue
def issueKey = "PAP-39"
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject(issueKey)

log.debug("Roles: ${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectsByName("Add Roles")[0])}")

It successfully prints:

 Roles: [8, 9] // The options I selected in the Database Picker

 as expected.

Why does the same piece of code not work in post function, but in Script Console? I can confirm that the field is not hidden or read-only, and printing other fields in the post function using the same syntax always works.

1 answer

1 accepted

0 votes
Answer accepted

Found the answer here right after posting this...

It appears that I need to set the post function to be processed AFTER the issue is created and re-indexed, etc.

QQ截图20200907211713.png

Hope this helps.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

73 views 1 6
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you