Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

setCustomFieldValue (integer)

admin_tt July 3, 2018

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!

2 answers

2 accepted

1 vote
Answer accepted
Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 2018

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)
Михаил Дорохин July 3, 2018

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! 

1 vote
Answer accepted
Roland Holban (Adaptavist)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 2018

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. 

Suggest an answer

Log in or Sign up to answer