简体   繁体   中英

Set a customField Value in JIRA with Groovy JAVA

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 
}}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM