Hi there,
I am trying to update a custom field called Urgent based on another calculation, my script works fine until I try to update the custom field on the issue. It just doesn't seem to set this correctly.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import java.util.Date.*
import com.atlassian.jira.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.issue.fields.CustomField;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.sql.Timestamp
import java.util.concurrent.TimeUnit
import com.atlassian.jira.issue.customfields.manager.OptionsManager
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
IssueManager issueMgr = ComponentAccessor.getIssueManager();
CustomFieldManager fieldmgr = ComponentAccessor.getCustomFieldManager();
def issue = issueMgr.getIssueObject("IssueKey")
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObject('customfield_11202');
def datenow = new Date()
def issduedate = issue.getDueDate()
def calculation = (issduedate - datenow)
def cfurgent = customFieldManager.getCustomFieldObject("customfield_13700")//checkBox
def fieldConfig = cfurgent.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Urgent", null)
if (calculation < 90)
{issue.setCustomFieldValue(cfurgent, option)}
else
{return 'no'}
issue.store()
I am running this from the console hence calling getissueobject, if I comment out after the if it gives me "urgent" so it is finding this option, urgent is the only option on this field.
but this line doesn't seem to set it
{issue.setCustomFieldValue(cfurgent, option)}
ultimately this will go on a workflow transition but I would like to get it working in the console first, any ideas what I'm doing wrong, I have read lots of posts before about this but can't get it working.
Hello!
Checkbox fields have to be handled a bit differently. Here's an example script of how to set the values in a checkbox field:
import
com.atlassian.jira.component.ComponentAccessor
def
customFieldManager = ComponentAccessor.customFieldManager
def
optionsManager = ComponentAccessor.optionsManager
def
issueManager = ComponentAccessor.issueManager
def
issue = issueManager.getIssueObject(
"issue_key"
)
def
customField = customFieldManager.getCustomFieldObjectsByName(
"checkbox_name"
)[
0
]
def
fieldConfig = customField.getRelevantConfig(issue)
def
options = optionsManager.getOptions(fieldConfig)
def
optionsToSet = options.
findAll
{ it.value
in
[
"option_name1"
,
"option_name2"
,
"etc"
] }
issue.setCustomFieldValue(customField, optionsToSet)
Hopefully this helps you out, please let me know if you have any other questions. :)
Jenna
Hi Jenna,
thank you, it worked! I appreciate you spending your time writing this out for me :)
Kind regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm glad it's working for you! :)
If you're happy with my response to this I would greatly appreciate if you could accept it the answer on this question. This let's other people know this question has a correct response so that they can hunt down answers to their questions faster.
Thanks!
Jenna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jenna Davis Is there a way to do this using JMWE? I'm trying to use the configure field option as a post function on a workflow when an issue is transitioned into a specific status.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I responded to that question on: https://community.atlassian.com/t5/Jira-questions/Check-a-Box-with-a-Postfunction/qaq-p/1443274
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jenna Davis ,
Have you ever done this for Cloud?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I found how to do it:
issueInput.fields.customfield_10097 = [[value: '1'],[value:'2'],[value:'3'],[value:'4']]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This only works for a Post Function. How would you do it within a Listener?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.