Updating custom fields in post function groovy script

Hi

I am using groovy script as a post function on issue creation to set a few user picker fields. It works fine and I see the fields updated after issue creation is done. However if I try to use these fields in consequent post function in the same transition (create) they appear to be null. For example I tried to copy updated field or send email to user set by groovy but fields reported to be null. So it looks like fields updated by groovy script is not visible for the subsequent post function in the same transition. Is there any reason for that or am I doing something wrong ?

1 answer

IIt sounds like the data isn't being saved and/or you are loading the original issue in the second post function.

Make sure you save the updates in the post function (maybe try a reindex too if that fails).

 

and try defining your issue this way.  This one resolved a lot of my issues similar to this one in older versions.

MutableIssue issue  = (MutableIssue) issue;

I'm storing issue with issue.store() and I did use MutableIssue. In my postfunction list on creation I have

  1. Creates the issue originally
  2. My Groovy script setting Approver 1, Approver 2
  3. Re-index an issue to keep indexes in sync with the database.
  4. Copy Approver 1 -> Approver
  5. Fire a Issue Created event that can be processed by the listeners.

After issue is created I can see Approver 1 and 2 set as expected but not the Approver sad

 

Sorry I didn't see your reply.  It is worth noting that in my experience issue.store() only really works on native fields and for custom fields you either have to update them with

myCF.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(myCF), ThisValue), changeHolder); }

or if you use the issue.setCustomFieldValue() then use

issueManager.updateIssue(userUtil.getUserObject('automation'), issue, EventDispatchOption.DO_NOT_DISPATCH, true);

 

 

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

60 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