首页 > 解决方案 > Scriptrunner 行为:当我选择特定的单选按钮选项时,如何使自定义字段成为必需?

问题描述

版本 - Jira v8.5.1 的行为

几个月来,我一直在使用 Beavhiours 脚本并取得了巨大的成功。它目前根据用户选择(列表、级联列表、复选框)显示/隐藏各种字段。我想根据单选按钮的值来调整文本字段的必需/可选条件。

是:当我做出正确的单选按钮选择时,文本字段必需的状态不会改变应该是:当我选择特定的单选按钮时,文本字段应该成为必需的

目标:当 1. 单选按钮 (radioField) 和 2. 级联列表 (listField) 都满足特定选择条件时,使用 Adaptavist Behaviors 使 textField 成为必需。

这是我在“行为”“字段”之一中的示例代码:

// set pointers to custom fields (list, radio button, and text)
def listField = getFieldByName ("My List")
def radioField = getFieldByName ("My Radio")
def textField = getFieldByName ("My Text")

// get cascading list value (parent and child)
String listString = listField.getValue()
// if cascading list matches one of two selections, show the radio button field
if ((listString == "[Parent1, Child1]") || (listString == "[Parent1, Child2]")) {
    radioField.setHidden(false)
} // otherwise, hide the radio button field
else {
    radioField.setHidden(true)
}
// get the value of the radio button field
String radioString = radioField.getValue()
// if both the cascading list and radio button value match specific values, make the text field required
if ((listString == "[Parent1, Child1]") && (radioString == "Radio Option")) {
    textField.setRequired(true)
}
// in all other cases, make the text field optional
else {
    textField.setRequired(false)
}

除了使文本字段成为必需之外,此代码有效。我可以通过以下步骤获取所需的文本字段:

  1. 将 listString 设置为“[Parent1,Child2]”
  2. 将 radioString 设置为“无线电选项”
  3. 将列表字符串设置为“[Parent1, Child1]” 在这种情况下,我们选择一个显示单选按钮字段但不满足使文本字段成为必填条件的列表选项(“[Parent1, Child2]”)。然后我们可以将单选按钮设置为正确的选项。然后将列表选项设置为满足使文本字段成为必需的第二个条件(“[Parent1,Child1]”)的选项。

鉴于这种行为,似乎只有在我更改列表字段选择时才会更新单选按钮字段值。但它不应该独立于我的列表选择吗?

附加信息:当我更改选择时,我的单选按钮都不会更新它们的值。我通过在单选按钮值上使用 log.warn 来确定这一点,然后检查内置脚本“查看服务器日志文件”的“atlassian-jira.log”最后几行中的打印语句。单选按钮保持在其默认。

标签: jirajira-pluginjira-integrationautomation-for-jira

解决方案


推荐阅读