Setting issue values in a post function to display values on email.

Hi all,

I'm using the script runner plugin to write some post functions for my JIRA instance and i've run into a bit of a problem. I am setting some values returned from a web service into some fields on my issue at the point it is created. The value i am setting should then appear in the header of an email. Previously i've done this with the value being entered into the same field in JIRA directly and that works correctly so i know the velocity template update i have implemented is correct. The issue i am having is that the velocity templates appear to not be able to see the updated field, so i am getting an email value which comes out something like this:

myProject / $issue.getCustomFieldValue("customfield_10301") / XYZ-123456

instead of: 

myProject / myWebServiceValue / XYZ-123456

I am setting the value in the first post function that is actioned after the initial create post function. I am using the following function to set the value within the groovy script:

tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), nodes.item(0).getNodeValue()),changeHolder)

(it's being pulled out of the service response using xpath, hence the nodes item). I've used this function before and it usually persists changes across various post function scripts so i'm not sure why it should be any different for the email generation if the update is made to the issue before the event fires in the post functions. Any help with this would be much appreciated. Thanks.

1 answer

1 accepted

If you are in the first post-function you should use simply:

issue.setCustomField( cf, "whatever" )

you don't need the changeholder stuff. You need that if the issue has already been stored and indexed by the time your post-function runs.

That you see the velocity stuff in the email suggests that the value was null... check for errors in your log, maybe mail log.



This was the problem, i swapped my previous set code for this code on this field so now I use: issue.setCustomFieldValue(tgtField, nodes.item(0).getNodeValue()) and the email title generates correctly. I don't fully understand how this differs from the other function with regards to the data the email then uses to generate as previously the value was definitely populated on the issue and there were no errors in the logging when populating it/during email generation so I'm not sure I understand why this fixed it but it has. Thanks for your help Jamie, much appreciated.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,701 views 3 11
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