Forums

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

How do I get the value that was added to the Multiple User Picker type field?

Mari Pervushina
Contributor
July 26, 2024

Hi everybody.

I really need help with solving the following problem. The function works in the cloud: "{{addedfieldChange.valueIds}}". But this does not work in the Data Center. The task is as follows. Users add other users to the Multiple user Picker type field. I need to track the change of this field and get the value that was added in order to add or remove it from other similar fields. But I can't get the value that was added by using {{fieldChange.fromString}} and {{fieldChange.toString}} .

5 answers

1 accepted

3 votes
Answer accepted
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.
July 29, 2024

Hi @Mari Pervushina 

I am using Jira Cloud, and so cannot test my suggestions with Jira Data Center, so please test with your rules.  With that out of the way...

I recall the scenario you describe for Jira Data Center is difficult to solve because the changelog information available to automation rules is different from Jira Cloud's rules.

 

First, let's confirm if your rule has what it needs to solve this.  Please create the following test rule, run it with a test issue, and post what you see in the audit log details:

  • trigger: Value Changes for Multiple Users Picker
  • action: Add value to the audit log, with this:
From String values: {{#changelog.your Custom Field From The Trigger}}{{fromString}}{{/}}
  • action: Add value to the audit log, with this:
From values: {{#changelog.your Custom Field From The Trigger}}{{from}}{{/}}
  • action: Add value to the audit log, with this:
To String values: {{#changelog.your Custom Field From The Trigger}}{{toString}}{{/}}
  • action: Add value to the audit log, with this:
To values: {{#changelog.your Custom Field From The Trigger}}{{to}}{{/}}

If these correctly list the selected name changes, we can then create a rule using created variables with text functions to get the added and removed values isolated.

Kind regards,
Bill

Mari Pervushina
Contributor
July 29, 2024

Thank you @Bill Sheboy for your attention to my problem.

I did two tests. In the first one, I had an empty field and added one value "test user". In the second test, I added two values ​​Mari and Jira Admin to the same field. And this is what is in the logs.

2024-07-29_17-47-02.png

 

Mari Pervushina
Contributor
July 29, 2024

Нere are two more field changes. As you can see, the row is inserted according to alphabetical order.

2024-07-29_17-59-53.png

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.
July 29, 2024

Thanks for that information!  Here are two more tests to confirm the behavior before we try the rule:

GIVEN there are several users selected in the field
WHEN one user is removed
THEN that user is in the from changelog value
AND that user is not in the to changelog value

 

GIVEN there are several users selected in the field
WHEN all users are removed
THEN all the users appear in the from changelog value
AND no users appear in the to changelog value

 

Please try those and post the results.

 

Mari Pervushina
Contributor
July 29, 2024

1.

GIVEN there are several users selected in the field
WHEN one user is removed
THEN that user is in the from changelog value
AND that user is not in the to changelog value

2024-07-29_20-38-00.png

Mari Pervushina
Contributor
July 29, 2024

2.

GIVEN there are several users selected in the field
WHEN all users are removed
THEN all the users appear in the from changelog value
AND no users appear in the to changelog value

2024-07-29_20-39-50.png

 

Did I understand correctly what needs to be done?

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.
July 29, 2024

Thanks, and that confirms the {{fromString}} and {{toString}} may be used to correctly identify the values removed and added by user name.

 

First to summarize the approach: use the field's changelog values to create lists of the added and removed users, and then use those lists to build dynamic JSON to make changes to the other custom field.

 

This approach uses the create variable action several times, the text replaceAll() function with regular expressions, and list iterators to find the user changes.  Here are some details to help.

  • trigger: Value Changes for your Multiple Users Picker
  • action: Create Variable
    • name: varFromStringData
    • smart value: to initially get the from-values from the changelog
{{#changelog.your Custom Field From The Trigger}}{{fromString}}{{/}}
  • action: Create Variable
    • name: varFromUserNames
    • smart value: to remove any brackets and replace the delimiters
{{varFromStringData.remove("[").remove("]").replace(", ",",")}}
  • action: Create Variable
    • name: varRegExFromUsers
    • smart value: to create a regular expression testing for any from-values
({{varFromUserNames.replace(",","|")}})
  • action: Create Variable
    • name: varToStringData
    • smart value:  to initially get the to-values from the changelog
{{#changelog.your Custom Field From The Trigger}}{{toString}}{{/}}
  • action: Create Variable
    • name: varToUserNames
    • smart value:  to remove any brackets and replace the delimiters
{{varToStringData.remove("[").remove("]").replace(", ",",")}}
  • action: Create Variable
    • name: varRegExToUsers
    • smart value: to create a regular expression testing for any to-values
({{varToUserNames.replace(",","|")}})
  • action: Create Variable
    • name: varAddedUsers
    • smart value: delete any from-values from the to-values, leaving only the added users
{{varToUserNames.replaceAll(varRegExFromUsers,"").split(",").match("(.++)").join(",")}}
  • action: Create Variable
    • name: varRemovedUsers
    • smart value: delete any to-values from the from-values, leaving only the removed users
{{varFromUserNames.replaceAll(varRegExToUsers,"").split(",").match("(.++)").join(",")}}

 

I recommend only writing the values / variables to the audit log initially to confirm everything is configured correctly before trying the edit with the JSON.

 

Like Mari Pervushina likes this
Mari Pervushina
Contributor
July 30, 2024

@Bill SheboyThis is working brilliant!
Thank you so much! 

I'll figure out how it works, "split and join" a great solution.

Like Bill Sheboy likes this
Mari Pervushina
Contributor
July 31, 2024

@Bill Sheboy 

I have the question!

I add and remove the variable values ​​to other Multiple users -picker fields. The interesting thing is that "add" always works successfully, but "remove" only works if the user has added one new user to my field. If he added two or more users, then the “update” and “delete” functions will not work, although they will not generate an error.

How can i fix this? 

2024-07-31_11-29-47.png

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.
July 31, 2024

Those final created variables, varAddedUsers and varRemovedUsers, are comma-separated value lists of users.  They must be parsed to create the needed JSON syntax: 

https://confluence.atlassian.com/automation/advanced-field-editing-using-json-993924663.html

 

There are several possible edit scenarios (from the trigger issue's field) to handle:

  1. users added and users removed
  2. users added and no users removed
  3. no users added and users removed
  4. no changes (we can skip this one as the rule should not trigger)

And so the JSON must be dynamic to handle the different cases, and any comma delimiters.

{
"update: {
"customfield_10048" : [
{{#varAddedUsers.split(",")}}
{ "add": { "name": "{{.}}" } }{{^last}}, {{/}}
{{/}}

{{#if(and(varAddedUsers.isNotEmpty(),varRemovedUsers.isNotEmpty()))}}, {{/}}

{{#varRemovedUsers.split(",")}}
{ "remove": { "name": "{{.}}" } }{{^last}}, {{/}}
{{/}}
]
}
}

This one splits the varAddedUsers on the commas, and adds an entry for each one {{.}} to add it.  Note that this uses the {{^last}} list syntax to dynamically add comm-delimiters, except for the last one.  That is handled with...

Then it checks if both varAddedUsers and varRemovedUsers are not empty so it can add a comma between them.

Finally, it does the same thing for the varRemovedUsers.

 

Mari Pervushina
Contributor
July 31, 2024

@Bill Sheboy 

I don't care which users were removed from the field, so I only use the "varAddedUsers" variable. Can I use JSON like this?

 

{
"update: {
"customfield_10048" : [
{{#varAddedUsers.split(",")}}
{ "remove": { "name": "{{.}}" } }{{^last}}, {{/}}
{{/}}
]
}
}

 

I'm doing something wrong in this option, as the rule returns the following error "Error while parsing additional fields. Not valid JSON."

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.
July 31, 2024

Do you only want to add the new users?  If so, replace "remove" with "add".

Next, have you confirmed there are users to add before attempting to make the edit?

Finally, to help diagnose this, please write that entire expression to the audit log.  That will help to confirm if there is something invalid in the JSON.

 

Mari Pervushina
Contributor
August 2, 2024

@Bill Sheboy 

Thank you.

It seems that earlier I made a mistake somewhere in parentheses or commas and now everything is working for me. A piece of code is below in the post

Like Bill Sheboy likes this
Mari Pervushina
Contributor
August 2, 2024

@Bill Sheboy 

Thanks for pointing me in the right direction! I found a solution. It works at Data Center:

 

{
"update":
{
"customfield_10048" :
[
{{#AddedStudents.split(",")}}{"remove": {"name":"{{.}}"}}{{^last}},{{/}}{{/}}
]
}
}
Like Bill Sheboy likes this
0 votes
Mari Pervushina
Contributor
August 6, 2024

Hello everyboody!

Another problem confronted me. I will describe it in a separate thread, maybe it will be useful to someone else.

Some users have user name = Full name, I tested it on them and everything was fine. But now I see that my method described above does not work if the user has user name = email. I was thinking of trying to use To/From instead of StringTo/From, but the id part contains ":" and that seems to be the problem. Then I decided to use a webhook request to receive the user name and then work with it. I know how to do this in automation using the standard "Send web request" function and am now looking for a way to do it in a loop.

Mari Pervushina
Contributor
August 6, 2024

First I try to use custom data. And I have no idea why this doesn't work?

2024-08-06_17-21-27 (2).png

2024-08-06_17-24-03.png

 

I used this article 

https://confluence.atlassian.com/jirakb/how-to-send-a-webhook-from-an-automation-rule-using-assets-object-data-1130372732.html

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.
August 6, 2024

Hi @Mari Pervushina 

You appear to be calling the Jira REST API endpoint for Find Users.  Is that correct?

https://docs.atlassian.com/software/jira/docs/api/REST/9.13.0/#api/2/user-findUsers

If so, please try passing the query parameters on the URL rather than using custom data.  This one worked for me with Jira Cloud and I suspect it is similar for Data Center.

yourJiraURL/rest/api/2/user/search?query=username="{{fullName}}"

 

Kind regards,
Bill

Mari Pervushina
Contributor
August 6, 2024

Hello @Bill Sheboy , you are right, this is working. But my plan was to pass the variable not in the url line, but in "Custom data", so that in my case it would be possible to get the username for several users one by one.

 

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.
August 6, 2024

If the user names are comma-separated values (CSV), this seems to work, probably up to some search limit of 50 users:

yourJiraURL/rest/api/2/user/search?query=username="Alice","Bob","Eve"

And so if your input can be made into a CSV list, with surrounding quotation marks, please try that approach.

Mari Pervushina
Contributor
August 6, 2024

Query parameters must be transmitted in encoded form. That's why I did it this way. The variable contains a string with fullname. If there is only one name, the request works and returns username. If I pass several values ​​separated by commas, the response body is empty.

2024-08-06_20-23-47 (2).png2024-08-06_20-24-48 (2).png

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.
August 6, 2024

Again, I am using Jira Cloud and not Data Center, and so cannot test what I am suggesting...

Perhaps try splitting the values, encoding, and then joining them with commas.

Mari Pervushina
Contributor
August 7, 2024

Hello @Bill Sheboy 

I checked by simply entering a request in the URL line. No encoding is required with this request. Search for one meaning works. If I enter several meanings, the query tries to find a match and does not find it, it does not perceive this as several different requests. And this does not contradict the documentation, since it is indicated there that the response can contain many users. For example, I indicated John, all John's will be returned to me.

In this regard, I will try to take a different route. I will split the string I received into several values ​​using split. And for each I will execute a separate web request. In this option, I am confused by the cumbersomeness and the fact that I don’t know how to get more than two values ​​​​through split ({{***.split(',').first}}, {{***.split(',').last}})

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.
August 8, 2024

You are using Jira Data Center's version of automation, and that does not have advanced branches yet, so I am unclear how you will iterate over the values.

Assuming you have figured out a way to do this...

When splitting a list, the get() function may be used.  That is 0-based, and so:

  • first entry: {{somevalue.split(",").get(0)}}
  • second entry: {{somevalue.split(",").get(1)}}
  • ...

https://confluence.atlassian.com/automation/jira-smart-values-lists-993924868.html#Jirasmartvalueslists-list.getlist.get(index)

Mari Pervushina
Contributor
August 9, 2024

Super! Thank you very mash @Bill Sheboy 

0 votes
Mari Pervushina
Contributor
July 29, 2024

I need to get added values for multipl users-picker field, i need the value of difference between From and To as username. My automation bellow.

 2024-07-29_12-45-21.png

///

2024-07-29_12-46-41.png

 

And the variable StudentName = {{fieldChange.toString.diff(fieldChange.fromString)}} returns Empty, see log bellow.

2024-07-29_12-52-35.png

 

Mari Pervushina
Contributor
July 29, 2024

I understand that the variable {{fieldChange.fromString}} returns a string and it will not be possible to use a minus or a difference here. But I don’t know what I can use.

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.
July 29, 2024

Hi @Mari Pervushina 

The diff() function only applies for date and date / time values, and not for text: https://confluence.atlassian.com/automation/jira-smart-values-date-and-time-993924864.html#Jirasmartvaluesdateandtime-diffdiff(date)

Kind regards,
Bill

0 votes
Trudy Claspill
Community Champion
July 28, 2024

Hello @Mari Pervushina 

When you ask for help with an Automation Rule, in order for us to provide help we need you to provide the following:

1. Screen images that show your entire rule and the details of each step.

2. The details from the Audit Log for an execution of the rule.

0 votes
Samuel Gatica _ServiceRocket_
Community Champion
July 26, 2024

Hi @Mari Pervushina 

Please check similar issue described here

 

Best regards

Sam

Mari Pervushina
Contributor
July 28, 2024

Hello @Samuel Gatica _ServiceRocket_

Thank you for you advice. I wrote my question in here.

There is no answer to my question right now and this topic about cloud instead my problem only for data center.

Suggest an answer

Log in or Sign up to answer