Hi, Community!
I need your help with a little something.
I'm trying to pull the name and surname from the reporter's email for better automated messaging. I'm testing the following part of this automation for now:
Log action:
Matching result is {{issue.reporter.emailAddress.match("[^\W\d_]+(?=.*@)")}}.
The regex in the match function is supposed to grab any words (any strings that are not [^ made of non-word characters \W, digits \d or the underscore characters _]) before the @ mark and return them as matching results in an array. See regex101 here - it does what it should with Java 8 Engine. Smart values documentation links to Java 7 documentation, but the same character classes are listed there
Anyway, the problem is that my logs keep returning just
Matching result is
I tried putting the regex with and without the quote marks and nothing works.
I also tried {{issue.reporter.emailAddress.match("[^\W\d_]+(?=.*@)").first}} and {{issue.reporter.emailAddress.match("[^\W\d_]+(?=.*@)").get(0)}} without any success.
{{reporter.emailAddress}} is logged correctly.
All help is appreciated.
The documentation for the match() function states that the regular expression search's "underlying implementation is based on Java's Pattern class", however my experience and several other community posts indicate it does not support all of the features: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#match--
I recommend doing some testing and writing to the audit log, starting with the simplest possible expression that can work to extract the name.
Next, I believe match() returns an array, not a list. As a result you may need to use the split() and other text functions to convert the value into a list before trying to use get(). For example, to remove any square-brackets which the arrays use. Once again, incrementally implementing and writing to the audit log help to make progress.
Kind regards,
Bill
Hi @Bill Sheboy
Thanks for the hints, they actually got me to check the documentation again and this led me to the solution.
The documentation clearly states that the function returns matching groups and my regex did not return any groups, only direct matches.
Modifying the regex to return groups (like shown below) actually got it to work to some extent, so now I have a foothold!
([^\W\d_]+)(?=.*@)
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Firstly, you can get the name of the reporter using {{reporter.displayName}}.
Assuming you are following US standard of displaying the names i.e. FirstName MiddleName/ MiddleInitial LastName, you can try this using 'substring'
For FirstName, try {{reporter.displayName.substringBefore(" ")}}
For LastName, try {{reporter.displayName.substringAfterLast(" ")}}
Hope this helps.
Thanks,
Vamsi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for taking the time and thinking about my problem.
Sadly, it's quite often that in our JSM the users do not have an account, so their DisplayName is actually their email. This automation is meant especially for those cases where Display Name is not an option.
Cheers,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Understood.
Is there a specific pattern that you follow when assigning the email addresses or is it random? I mean, if all the users are part of the same organization, sometimes the pattern will be like firstname.lastname@orgname.com.
Thanks,
Vamsi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again,
Our JSM users are actually customers reaching out to us, so their email can be anything that can constitute an email address, all special characters and all domains are game, there's no real pattern. That's why I went for such a broad exclusion of characters.
I know it won't be foolproof, but I want to have at least some progress with this.
Cheers,
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.