Evening!
I'm looking for a way to pass an integer to a custom field in a scripted post-function (ScriptRunner).
Something like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def pass_the_zero = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Pass_the_Zero");
def pass_the_one = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Pass_the_One");
def pass_the_two = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Pass_the_Two");
issue.setCustomFieldValue(pass_the_zero, 0);
issue.setCustomFieldValue(pass_the_one, 1);
issue.setCustomFieldValue(pass_the_two, 2);
It looks like I have to convert my object into an integer, but I don't know how to do this. Any ideas?
Thanks!
Hello @admin_tt
As @Roland Holban (Adaptavist) says you code is correct and will work, but with certain condition.
This post-funstion must be placed right before "Update change history for an issue and store the issue in the database." post-function that will write changes what was done during transition
If you need to place it lower, you need to modify your script like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def pass_the_zero = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Pass_the_Zero");
def pass_the_one = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Pass_the_One");
def pass_the_two = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Pass_the_Two");
issue.setCustomFieldValue(pass_the_zero, 0);
issue.setCustomFieldValue(pass_the_one, 1);
issue.setCustomFieldValue(pass_the_two, 2);
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
Morning!
My bad: I've just noticed that I was trying to pass an int to a Number-field, and "0" is not a float. This is the root of the problem, I guess.
Thanks for your reply!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Im not understanding your question. The way you are doing it in your scrip is correctly setting the value of those custom fields to integers.
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.