Jira Smart value to extract first name from email address and then capitalise first letter

Sami Ullah May 8, 2024

We use automation to send reminder emails (ITIL 3 strike rule) to customer/ticket reporter. The email message starts with "Hi Firstname". Below code does that for us.

{{issue.reporter.emailAddress.substring(0,1).toUpperCase()}}{{issue.reporter.emailAddress.substring(1, issue.reporter.emailAddress.indexOf("."))}}

 

Cheers,
Sami

14 answers

1 vote
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 9, 2024

You may use the capitalize() function, adding it to the end of the expression:

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#capitalize--

0 votes
Dee Minty May 23, 2024

Hi Bill,

I'd like to give you an update that my issue can be fixed by 

{{issue.customfield_10132.substringBefore(".").capitalize()}} that @Sami Ullah used. 

Thank you so much for your help. 

Best Regards,

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2024

I notice your rule uses the Issue Created trigger.  That trigger can fire so quickly that the issue data is not yet available to the rest of the rule step.  This can cause problems, such as apparently empty fields.

I recommend adding the Re-fetch Issue action immediately after the trigger.  That will slow down the rule a bit, reloading the data before it proceeds.

 

Your email body references the smart value {{Employee First Name}}.  Where does that come from?

 

Next, as you identified the correct custom field id, customfield_10132, let's stick with that rather than alternating with the field name, Personal Email.

Using the Log rule action to write to the audit log, please write each of the following with a separate action for each, and describe what you observe when testing the rule with your example email address in the field, john.wick@a.com:

 

only the field: {{issue.customfield_10132}}

splitting the field: {{issue.customfield_10132.split(".")}}

number of items split from the field: {{issue.customfield_10132.split(".").size|0}}

first name from split field: {{issue.customfield_10132.split(".").get(0)}}

 

What you should expect to see in the audit log is:

  • only the field: john.wick@a.com
  • splitting the field: john, wick@a, com
  • number of items split from the field: 3
  • first name from split field: john

 

If you do not see those please recheck that the smart values are correct.

 

0 votes
Dee Minty May 23, 2024

Hi Bill,

Version: I'm not sure about the version but this is an ITSM

Project type : Service management
Field: It's a custom text field

Screenshot 2024-05-23 142622.pngScreenshot 2024-05-23 143909.png

I'd like to show only John Wick in the email.

Screenshot 2024-05-23 144012.png

I hope I provide the right information.

Thank you. 

Best Regards,

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2024

Solving problems with automation often requires understanding the context of the rule actions.  Please answer / post the following to clarify the rule context:

 

(1) What version of Jira are you using: Jira Cloud, Server, or Data Center?

(2) If using Jira Cloud, what type of project is this: team-managed or company-managed?  You may find that information at the bottom-left side of the page expanding area, or by looking at the type in the list of "View All Projects".

(3) What is the type of your custom field: text, user selection, something else?

(4) Please post an image of your complete automation rule.

(5) Please post an image of your audit log details showing the rule execution.

 

Thank you.

0 votes
Dee Minty May 23, 2024

Hi Bill,

Our email addresses use a period to separate the first and last name (e.g., john.wick@a.com). However, as shown in the picture below, the first two examples display the entire email address correctly. The last one, highlighted in grey with a period (".") shows nothing.

Thank you.

Best Regards, 

Screenshot 2024-05-23 105857.png

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2024

Is your split(" ") as you just posted, or with the period in the email address: split(".")?

Please post images of your complete rule and of the audit log details showing the rule execution.  Those may provide context to help explain what you are observing.

0 votes
Dee Minty May 23, 2024

Hi Bill,

I’ve tried using {{issue.customfield_10132}} and {{issue.Personal Email.split(" ").get(0)}}. Both work, but the entire email address is still displayed in the email.

Do you have any suggestions?

Thank you.

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 22, 2024

Let's try this: write just that custom field to the audit log to confirm what it contains:

{{issue.customfield_10132}}

Once we know that we can adjust the smart value expression.

0 votes
Dee Minty May 22, 2024

Hi @Bill Sheboy 

Thank you for your reply, I found the custom field id and use it as in the capture screen below, but it still cannot show first & last name from the email address in the email. 

Not sure what did I do wrong. 

Please advise

Thank you. 

Best Regards, 

Screenshot 2024-05-22 171048.png

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 22, 2024

Hi @Dee Minty 

This technique works for text smart values.  If your field is text, this may work:

{{issue.personal email.split(".").get(0)}}

If not, are you certain you have the correct smart value for your field?

Smart values are name, spacing, and case-sensitive, and do not always exactly match the displayed field name on the issue views.  To confirm you have the correct one, you may use the how-to article below.  The essential steps are:

  • identify an example issue that has your field
  • using a web browser tab, call the REST API function see all smart values:
yourJiraURL/rest/api/2/issue/yourIssueKey?expand=names
  • search for your field on the page, such as with Control-F for find
    • if you find your field, you will see the correct smart value, or custom field id
    • if you do not find your field, it may not be supported by automation rules

https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/

Kind regards,
Bill

0 votes
Dee Minty May 22, 2024

Hi Bill,

Will this work with a custom field? We have a custom field named 'personal email,' which value in this an email address format firstname.lastname@domain.com and we are trying to split the first and last name from it to display in the email when it is sent automatically from the automate rule. However, I tried as below, and it doesn't seem to be working.

{{issue.personal email.emailAddress.split(".").get(0)}}

{{issue.personal email.split(".").first}}

Please advise. 

Thank you.

0 votes
Sami Ullah May 8, 2024

Thanks @Bill Sheboy How do you capitalise first letter in this code?

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 8, 2024

Hi @Sami Ullah 

If your email addresses are in the format of firstName.lastName@domain then you could split on the period and take the first entry:

{{issue.reporter.emailAddress.split(".").get(0)}}

Please look here to learn more about those rule features:

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events