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.