Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Adding custom field to email under "Send a custom email"

Søren Hansen December 16, 2022

Hi 

I am using a scriptrunner and their build in scripts. Under Workflows I have made a Post Function using their build in "Send a custom email".

I have made the email in HTML and added the $issue.key $issue.summary to the Subject - So that JEHM will se the email if the client responds to the email.

I works very well, byt i want to ad som flair.

The Client email is in a custom field, and i want the email to say:

Dear Customername

I have used:

${issue.fields.customfield_XXXXX}

but it does not work? Also how do i remove the @email.com from the custom filed?

Do I need something in the "Condition and Configuration"

Send custom email.png

2 answers

2 accepted

2 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
December 20, 2022

Hi @Søren Hansen

For your requirement, you could try something like:-

Dear <% out << issue.getCustomFieldValue(customFieldManager.getCustomFieldObject('customfield_14840')).toString().substring(0, issue.getCustomFieldValue(customFieldManager.getCustomFieldObject('customfield_14840')).toString().indexOf('@')).trim() %>

Basically, the sample code above is using the String object's substring method to trim the String starting from the @ symbol. 

Then only issue is that you will need to add the entire method call because it is not possible to use an object reference in this.

Below are a few test screenshots for your reference:-

1. When the issue is created, the sample email john.williams@gmail.com is added to the Text Field

test1.png

2. When the issue is created, the Sample Text field is displayed and a sample comment is added

test2.png

3. Finally, when the email is sent out, the email address is truncated starting from the @ symbol only displaying the recepient's name. 

test3.png

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Søren Hansen December 20, 2022

very nice. Thank you.

Like Vikrant Yadav likes this
1 vote
Answer accepted
Vikrant Yadav
Community Champion
December 16, 2022

Hi @Søren Hansen For custom fields try to use following code :- 

Dear <% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14840")) %>

 Thanks

V.Y

Søren Hansen December 18, 2022

It works. But how do i remove the "@mail.com" part :-)?

Like Vikrant Yadav likes this
Vikrant Yadav
Community Champion
December 19, 2022

@Søren Hansen  is it user picker field or single line text field? 

Søren Hansen December 19, 2022

It is a text field. 

JEHM  takes the email from the sender and puts it this custom field.

Vikrant Yadav
Community Champion
December 19, 2022

okay, thanks for sharing the field type. I am not sure, how to split name from email address. Let me add Scriptrunner expert who can help you.

@Ram Kumar Aravindakshan _Adaptavist_  Kindly help us in removing "@mail.com" part from text field.

Thanks

Suggest an answer

Log in or Sign up to answer