OK, so i'm probably overlooking something simple, but here we go:
I've used Jamie's example to prefill a field with static info.
BUT; i would like to use it to show some dynamic info as well.
So instead of:
def desc = getFieldById("customfield_10123") def defaultValue = """ Hi question-asker, Thanks for your question. With kind regards, Edwin. """.replaceAll(/ /, '') if (! underlyingIssue?.description) { desc.setFormValue(defaultValue) }
def desc = getFieldById("customfield_10123") def name = (getfieldByID("customfield_10102") def defaultValue = """ Hi $name, Thanks for your question. With kind regards, Edwin. """.replaceAll(/ /, '') if (! underlyingIssue?.description) { desc.setFormValue(defaultValue) }
What am i missing?
In addition, i would like to add a dynamic part as well.S
So if customfield_10103 == Male,
it should say Hi mr. $name.
In case customfield_10103 == Female,
It should say Hi mrs. $name.
Any pointers?
Thanks in advance guys
getfieldByID has incorrect casing - you can see that it's different from the first example. Also there is an errant opening bracket.
def name = getFieldById(
"customfield_10102"
)?.value?.value
should give you the name, and the rest should work.
NB the first getValue() gives you the form value which is an Option object, the second getValue() gives you the string value of the option.
Check your logs too, your example should have produced a compile error.
Hi Jamie,
Thanks for your reply. I get an error when using the provided example:
Screen Shot 2016-09-19 at 13.27.31.png
I checked the logging as well, and i could retrieve the following:
2016-09-16 23:06:54,076 http-nio-8080-exec-19 ERROR edwin 1386x74525x1 lqq16g 87.214.233.222,0:0:0:0:0:0:0:1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/validators.json [c.o.jira.behaviours.BehaviourManagerImpl] Script function failed on issue: issue: TEST-84, user: edwin, fieldId: __init__, file: <inline script> groovy.lang.MissingMethodException: No signature of method: Script1.getFieldByID() is applicable for argument types: (java.lang.String) values: [customfield_10102] Possible solutions: getFieldById(java.lang.String), getFieldByName(java.lang.String) at Script1.run(Script1.groovy:6)
So i could have noticed the Id instead of the ID.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
Any ideas regarding the type checking?
Do you assume that the custom field type is a User Picker and/or Select List? In this case, it's a single text field.
Cheers,
Edwin.
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.