I'm trying to set the value of a custom numeric field using a Script Listener in Jira 7.
My script is running, and not generating any errors, but it is not writing to the desired custom field.
Right now it's just a preliminary test to figure out how to write to a custom field, so there's an arbitrary value in the below script.
What am I doing wrong?
Note that I've verified that the condition in the last if statement is being met and the code is executing without error.
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult;
import com.atlassian.jira.bc.issue.IssueService.IssueResult;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.util.UserManager
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10109");
IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.addCustomFieldValue(customField.getIdAsLong(), "123456");
ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
if (!loggedInUser) {
loggedInUser = UserManager.getUserByName('jira_bot')
}
UpdateValidationResult validationResult = issueService.validateUpdate(loggedInUser, event.issue.getId(), issueInputParameters);
if (validationResult.isValid()){
IssueResult result = issueService.update(loggedInUser, validationResult);
}
Your code looks sound. You're absolutely certain the final condition result is valid? Keep in mind that the issue Service will ignore some invalid values, so it may not explicitely be telling you of some errors. Try to check the contents of validationResult.getErrorCollection() in your final if block in case there is anything there? Alternatively, print the validationResult.getFieldValuesHolder() information to make sure that the values you're trying to set are properly getting saved.
That's where i'd start and go from there.
Yes, the condition is definitely being met. I even changes the custom field id to an incorrect one to ensure it would throw an error in that case (which it did).
I've already tried using log.info with validationResult.isValid() both inside and outside the if statement, and they both logged true. I also logged validationResult.getFieldValuesHolder(), and I just got the empty array string: "[ ]"
However, I haven't tried looking at getFieldValuesHolder(). I'll try that and post the results. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I looked at the contents of the getFieldValuesHolder() and realized that my custom field wasn't showing up in there. I then realized that my custom field is behaving as a read-only field.
I've yet to figure out why that's happening, but trying to modify a different custom numeric field worked with the same script, so it looks like the script works at least.
Thanks for recommending that method--it provided the info I needed to figure out what was going on.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
is it a postfunction or is it running in the script console?
def Cf2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10109");
def changeHolder = new DefaultIssueChangeHolder() textCf2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(textCf2), myval),changeHolder)
try something like this to update the field
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.