我在编写ScriptRunner行为时遇到麻烦

时间:2020-02-05 09:19:51

标签: groovy jira

我试图设置两种行为,但这非常困难,因为我没有任何编码背景。这个想法是,凭单创建屏幕将根据用户的选择隐藏/显示字段。

因此,第一个行为应来自具有3个选项(SAP,Jira,其他)的下拉菜单,且下拉菜单的名称为“受影响的软件”。如果用户选择SAP,则会出现一个文本字段,称为“交易号”。如果他们选择其他,则应显示另一个文本字段,请输入软件名称。否则,这些文本字段将被隐藏而不显示任何其他字段。

这是我尝试编写的代码:

import com.onresolve.jira.groovy.user.FormField

FormField dropDown = getFieldByName("Affected Software")
FormField other = getFieldByName("Transaction Number")
FormField other = getFieldByName("Please enter software name")

if (dropdown.getFormValue() == 'SAP') {
    other.setHidden(false)
    other.setFormValue("SAP chosen")
} if else (dropdown.getFormValue() == "Other")
    other.setHidden(false) 
    other.setFormValue("Other chosen")
else {
 other.setHidden(true)
}

第二种行为比较简单。再次有一个下拉字段,称为这些选项是否有解决方法(是的,不,我不知道)。如果用户选择“是”,则将显示一个名为“解释解决方法”的字段。否则,什么都不会改变。

这是我尝试为该代码编写的代码

import com.onresolve.jira.groovy.user.FormField

FormField dropDown = getFieldByName("Is there a workaround?")
FormField other = getFieldByName("Explain the workaround")

if (dropdown.getFormValue() == 'yes') {
    other.setHidden(false)
    other.setFormValue("yes chosen")
} else {
 other.setHidden(true)
}

能否让我知道我做错了什么?预先谢谢你!

1 个答案:

答案 0 :(得分:0)

我认为您正在寻找的是getValue()而不是getFormValue(),因为这将为您提供基础值的ID,例如选项ID。