Hi all,
I would like another custom label field to set it's value based on another custom label field.
Here is my current code example:
def thisField = getFieldById(getFieldChanged())
def A= getFieldByName("A")
if (thisField.getValue() in (["123"]))
{
A.setFormValue("568")
}
This seems to work well for every other field type except custom label field :(
Any ideas?
When in doubt ... throw some debug message.
With behaviour, I like to use the setHelpText() for immediate visual feedback
def debugMsgs = []
def thisField = getFieldById(getFieldChanged())
def A= getFieldByName("A")
debugMsgs << "A= $A"
debugMsgs << "thisField = $thisField"
debugMsgs << "thisField.value = $thisField.value"
if (thisField.getValue() in (["123"]))
{
debugMsgs << "thisField.value found in (["123"])"
A.setFormValue("568")
debugMsgs << "A.value = $A.value"
}
A.setHelpText(debugMsgs .join('<br>'))
The one thing I would try different from your code is to remove the parens around ["123"]
Hey!
I gave your script a go and it's erroring out on the "123". Unfortunately as my groovy knowledge is "just beginner" I was unable to solve it :(
debugMsgs << "thisField.value found in (["123"])"
I did try setting different field type (Text) and all seemed to work great. And I have got single and multi select to work. I can also get the system label field to work, just not custom label fields to work. Are they not supported or a bug?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try it like this:
def debugMsgs = []
def thisField = getFieldById(getFieldChanged())
def A= getFieldByName("A")
debugMsgs << "A= $A"
debugMsgs << "thisField = $thisField"
debugMsgs << "thisField.value = $thisField.value"
def valueMap = ['123':'568']
if (valueMap.containsKey(thisField.value))
{
debugMsgs << "thisField.value found in ${valueMap}"
A.setFormValue("568")
debugMsgs << "A.value = $A.value"
}
A.setHelpText(debugMsgs .join('<br>'))
You'll want to change valueMap. The left side is the value in thisField" that triggers the 'right-side' label. If you have more, you add them comma sparated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This worked!
It does show the field should be receiving the values. But it still is not adding the label?
A= Form field ID: customfield_11858, value: 568
thisField = Form field ID: customfield_11052, value: 123
thisField.value = 123
thisField.value found in [123:568]
A.value = 568
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure what's going on there ... it's working for me.
Here I use the code exactly as is except for def A= getFieldByName("Theme")
The script is put against a random text field ... if I type "123" in my text field, I get this:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmmmmm I still cannot get it to work...
I wonder if it's a version issue of Jira/Script runner?
Code:
def debugMsgs = []
def thisField = getFieldById(getFieldChanged())
def A= getFieldByName("Region")
debugMsgs << "A= $A"
debugMsgs << "thisField = $thisField"
debugMsgs << "thisField.value = $thisField.value"
def valueMap = ['123':'USA']
if (valueMap.containsKey(thisField.value))
{
debugMsgs << "thisField.value found in ${valueMap}"
A.setFormValue("USA")
debugMsgs << "A.value = $A.value"
}
A.setHelpText(debugMsgs .join('<br>'))
Image:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Perhaps ... I do see a slightly different styling of your Label field than mine.
I'm on Jira 8.13.6 (Software+JSM)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can only think that it is a version issue.
Gonna do some digging and if I find something will post back.
But for now, thanks for the help. The debugging is super useful!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.