gpt4 book ai didi

java - 使用 Groovy JAVA 在 JIRA 中设置自定义字段值

转载 作者:行者123 更新时间:2023-12-01 09:23:09 26 4
gpt4 key购买 nike

好吧,也许我对此很陌生,但我正在尝试使用此代码,但它没有更新自定义字段值。

知道为什么不吗?我猜这是我的一个疏忽。非常感谢任何帮助

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
}

已解决

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

最佳答案

您的代码片段就目前而言,对我来说失败并出现以下错误:

Caught: groovy.lang.MissingMethodException: No signature of method: Custom.getTime() is applicable for argument types: () values: []

那里的 getTime() 没有被任何对象调用。我猜您只想在 customFieldsetCustomFieldValue,因此,不需要 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

关于java - 使用 Groovy JAVA 在 JIRA 中设置自定义字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40023975/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com