I'm using the Script Runner built in post function for "Send custom email" and it Previews without error when I test it in Script Runner, but when I use it in the actual workflow, I get this error regarding a custom field...
I use this field in several places (Condition, Email template, Subject template), and they all pass the "Preview" test. I can't find anything wrong with the way I'm putting this together, but I still get the above error. Is there anything else I can try?
Hi Thanos!!
I finally have it working!! Between your suggestions and information from the site
https://jamieechlin.atlassian.net/wiki/spaces/GRV/pages/33030148/Built-In+Scripts#Built-InScripts-Sendacustomemail
...I managed to put the pieces together and generate the desired email, without error, and including all the custom fields I wanted. (Once the problem was solved for the "ASID Number" custom field, it applied to the others).
Wherever I referenced the custom field(s) in the Email template or Subject template, I had to use this rather lengthy reference in order for it to pass the "Preview" AND show up in the generated email:
<% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("ASID Number"))%>
(Note that the "arrows" and the word "out" are part of the entire expression. I'm just mentioning this in case other members think that is some sort of corruption in the web display).
Thanks so much for all your help!!
Hi Chris,
Can you try to put the following script in the Condition and Configuration field
import com.atlassian.jira.component.ComponentAccessor
//get the customfield with name TextFieldA
def textFieldCF = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("TextFieldA")
//get the value of that customfield for the current issue
def textFielValue = issue.getCustomFieldValue(textFieldCF)
//store the value of that custom field in the config map and in position with key cfValue
config.cfValue = textFielValue
//condition should return true
true
And then you can call that value in the Email or Subject template fields, like
The value of TextField Custom field is ${cfValue}
Give it a try and please let me know if that did the trick.
Kind regards,
Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the quick reply, Thanos! Unfortunately, when I tried to put your suggestion into the Condition field, I got a message "No such property: config for class: Script15".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Chris,
Sorry I assumed you were in a more recent version.
In your case then try in the Subject or Email template something like
<%
def textFieldCF = com.atlassian.jira.component.ComponentAccessor.customFieldManager.getCustomFieldObjectByName("TextFieldA")
def textFielValue = issue.getCustomFieldValue(textFieldCF)
%>
Value of custom field is $textFielValue
Hopefully this will do the trick.
Regards,
Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks again, Thanos!!
The
def textFieldCF and def textFielValue portions worked for satisfying the Condition without getting any errors. That helped a lot!
However, no matter how I refer to $textFielValue in the email Subject or Body, I still get "No such property" errors. I've tried curly braces ${textFielValue} and other variations, but I can't seem to avoid the error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Thanos Batagiannis [Adaptavist] Could you please suggest how I could display a number without any decimal places?
Currently, I have a field which prints the field value in a single decimal format. I do not want to have any decimal places mentioned, as this particular number field value will never have any decimal places.
The following code works, however it prints the value along with the decimal part.
<% def totalsize = issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager()?.getCustomFieldObjectByName("Total Size"))
if (totalsize) {
out << "<p><b>Total Size: </b>" + totalsize +"</p>"
} %>
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.