We are on Jira Cloud.
OBJECTIVE: To retrieve the account id from the display names and update custom field.
USE CASE: When a user mentions another user(s) in an email reply to a work item these user names show as display names in Jira. I have an automation rule that filters out the display names, constructs email address. Then I use API call in Branches to get account ID for each email address.
MAIN ISSUE: Issue here is that in branching the custom field is not being edited because, as per my understanding, the variable in which account ID is stored resets each time values is added to it.
METHOD 1 (partially successful): USE SEND WEB REQUEST ACTION FOR EACH EMAIL ADDRESS TO RETRIEVE ACCOUNT IDs
I used Advanced Branching. For each email address API GET call is made to retrieve the account ID. AccountID is stored in a variable. JSON is used to update the custom field. JSON is stored in a variable and EDIT Action with Advanced Editing that contains the JSON variable. This ofcourse, doesn't work
Here are the complete steps followed by screenshots:
1. Trigger -> All Comments - Rule is run when a new comment is added to a work item
2. Create variable getDisplayNames filters the mentioned display names from the comment
Smart Value: {{comment.body.match("@(\\S+\\s\\w+)")}}
3. Create variable varEmailAdrs constructs email address from display names
Smart Value: {{getDisplayNames.split(",").trim().join("@domain.com,").replace(" ", ".")}}@domain.com
4. BRANCH
4.1 Create variable varEmailAdrsSplit splits the varEmailAdrs by comma (",")
Smart Value: {{varEmailAdrs.split(",")}}
4.2 SEND WEB RQUEST action
<API URL>/user/search?query={{varEmailAdrsSplit.urlEncode}}
4.3 Create variable apiResponseAccountId to retrieve the account ID
Smart Value: {{webResponse.body.first.accountid}}
4.4 Create Variable varJson value:
{ "update": { "customfield_10610": [ { "add": [ { "accountId": "{{apiResponseAccountId.trim()}}" } ] } ] } }
4.4 Edit Work Item, Advanced Editing {{varJson}}
I have no issues else where. API request is successful, the Audit Log shows "success". Just need to append the account IDs to custom field that is all!
Thanks!
Hi @IT Brute
Are you using Jira Cloud or Server / Data Center version?
And, are the people "mentioned" Jira users?
For Jira Cloud, user mentions in the comments contain the accountId values, and those could be used directly to create a dynamic JSON expression to update a multiple-selection user field in a single edit without any branching.
Or, do you mean someone is adding comments with email addresses rather than mentioning people using the built-in mention feature?
Kind regards,
Bill
@Bill Sheboy these are display names and not user names. Display names are just text strings. I have another automation rule where I achieve the same because users mentioned are user names.
We are on Jira cloud.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Would you please confirm how the mentions are entered in the comment? How are displayNames being entered as mentions?
For example, when one types @ followed by a Jira user's name, that is stored in the comment markup for a mention like this:
[~accountId:{{user selected.accountId}}]
Where an example from checking a specific {{comment.body}} could be:
[~accountId:557057:1d4fd7f4-bbac-4466-82ee-aaabbbccc]
In the UX, the user's displayName shows, but parsing the comment body should return the accountId value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy The issue is when the user doesn't use Jira's UI to add the user names.
'accountId' only comes in if the users are mentioned using Jira's portal. Mentioned below are two screenshots, one shows the reply from Outlook, the second shows comment mark up
The users mentioned in the comments are "TestUser 2" and "TestUser 3"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for that information, @IT Brute as it helps narrow down a possible workaround...
There are no bulk-get / search users by email addresses since the GDPR changes released a few years ago. And, after some quick experimentation, I could not find an endpoint which successfully returned multiple accountId values for a list of email addresses.
As you appear to be on a Premium license level, I hypothesize you have a larger number of users in the product, thus hardcoding is not an option for a rule.
One possible workaround is a using a recursive, multiple-rule approach, although it can be a brittle solution.
This approach will work for up to 10 email addresses, before the looping service limit happens.
If you can write / host your own service, a better workaround may be to write an app which can sequentially process the email addresses, and then just call that with Send Web Request.
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.
@Marc -Devoteam- Audit Log shows the "Issues edited successfully" but it clearly hasn't been, because the user names are not in the custom field. Screenshot below:
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.