Hi All
I created three custom fields for statistical data, in which the first and second fields are filled in manually by the user, and the third field automatically obtains the sum of the values of the first two fields, but I do not know how to assign values, the following is my code
Hi @arno
Instead of using Scriptrunner, did you try automation for JIRA if you have it ? It's usually easier to use this app for simple usecase like that.
If you need to use a script please have a look to
Regards
Hi @arno ,
I am not sure which feature you are using to achieve this, it looks like it might be a Listener, but this is something the Script Fields feature was built for. Firstly, just so we are on the same page, your current script can be made simpler using HAPI.
With HAPI, to get the custom fields, all you need to do is call the .getCustomFieldValue, you don't need the first section with:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def filed = customFieldManager.getCustomFieldObject('customfield_14300')
def filed1 = customFieldManager.getCustomFieldObject('customfield_14301')
def filed2 = customFieldManager.getCustomFieldObject('customfield_14302')
As HAPI handles that for you. Now, to update the issue with HAPI, you can find examples here, but the code looks like this:
issue.update {
setCustomFieldValue('filed2', c)
}
However, as I mentioned, this functionality is really something the Script Fields feature was build for. I have written a script to perform the functionality you require in a Script Field, which you can find here:
https://bitbucket.org/Adaptavist/workspace/snippets/Kdpy4e
Let me know if this helps!
Kind regards,
Bobby
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.