简体   繁体   English

使用Groovy JAVA在JIRA中设置customField值

[英]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: [] 捕获:groovy.lang.MissingMethodException:方法的无签名:Custom.getTime()适用于参数类型:()值:[]

That getTime() over there is not being invoked from any object. 那里的getTime()未被任何对象调用。 I guess you want only to setCustomFieldValue in customField , thus, cal.setTimeInMillis() ¹ is not needed: 我猜您只想在setCustomFieldValue中设置customField ,因此, cal.setTimeInMillis() ¹:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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