Reputation: 7117
Ok Maybe I am just really new at this, but I am trying to use this code and it is not updating the custom field value.
Any idea why not? I am guessing its an over sight n my end. Any help is greatly appreciated
def rush = getCustomFieldValue("Rush?")
if (rush=="Yes") {
def cal = new java.util.GregorianCalendar();
cal.setTimeInMillis(customField.setCustomFieldValue("Rush Date", getTime()));
return new java.sql.Timestamp(cal.getTimeInMillis());
}
else {
return null
}
solved
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
def componentManager = ComponentManager.instance
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
def customFieldManager = componentManager.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Rush?")
def rush = issue.getCustomFieldValue(cf)
def paymentDate = new Date()
if (rush?.value=="Yes"){
if (paymentDate){
def cal = new java.util.GregorianCalendar();
cal.setTimeInMillis(paymentDate.getTime());
cal.add(java.util.Calendar.DAY_OF_MONTH, 0);
return new java.sql.Timestamp(cal.getTimeInMillis());
}
else {
return null
}}
Upvotes: 0
Views: 1104
Reputation: 14559
Your snippet, as it stands, fails to me with the following error:
Caught: groovy.lang.MissingMethodException: No signature of method: Custom.getTime() is applicable for argument types: () values: []
That getTime()
over there is not being invoked from any object. I guess you want only to setCustomFieldValue
in customField
, thus, cal.setTimeInMillis()
¹ is not needed:
def customField
customField = [
'Rush?':'Yes',
setCustomFieldValue : { field, value -> customField[field] = value }
]
getCustomFieldValue = { customField[it] }
def rush = getCustomFieldValue("Rush?")
def cal = new java.util.GregorianCalendar()
def parseRush = {
if (rush=="Yes") {
customField.setCustomFieldValue("Rush Date", cal.getTime())
return new java.sql.Timestamp(cal.getTimeInMillis())
}
else {
return null
}
}
assert parseRush() == new java.sql.Timestamp(cal.timeInMillis)
assert customField['Rush Date'] == cal.time
Upvotes: 1