How do I get the value that was added to the Multiple User Picker type field?
Asked by Mari Pervushina:

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}} .


Answers:
author: Bill Sheboy
body: Hi [@Mari Pervushina](/t5/user/viewprofilepage/user-id/4996235)

*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](https://confluence.atlassian.com/automation/jira-smart-values-issues-993924860.html#Jirasmartvaluesissues-changelogchangelog) 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

comments: author: Mari Pervushina
body: Thank you [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) 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](https://community.atlassian.com/t5/image/serverpage/image-id/338568i323FBA507F26B2B3/image-size/large?v=v2&px=999 "2024-07-29_17-47-02.png")


author: Mari Pervushina
body: ?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](https://community.atlassian.com/t5/image/serverpage/image-id/338571i7558CCFDDDC435AD/image-size/large?v=v2&px=999 "2024-07-29_17-59-53.png")


author: Bill Sheboy
body: 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.


author: Mari Pervushina
body: 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](https://community.atlassian.com/t5/image/serverpage/image-id/338628i0A64DAA8A989D23C/image-size/large?v=v2&px=999 "2024-07-29_20-38-00.png")


author: Mari Pervushina
body: 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](https://community.atlassian.com/t5/image/serverpage/image-id/338630i15D97C75D9D3E39A/image-size/large?v=v2&px=999 "2024-07-29_20-39-50.png")

Did I understand correctly what needs to be done?


author: Bill Sheboy
body: 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](https://confluence.atlassian.com/automation/jira-automation-actions-993924834.html#Jiraautomationactions-create-variableCreatevariable) several times, the text [replaceAll() function](https://confluence.atlassian.com/automation/jira-smart-values-text-fields-993924863.html#Jirasmartvaluestextfields-replaceAllreplaceAll(Stringregex,Stringreplacement)) with regular expressions, and [list iterators](https://confluence.atlassian.com/automation/jira-smart-values-lists-993924868.html#Jirasmartvalueslists-examplesExamples) 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(",")}}
```

* action: Edit Issue
  * Finally, [advanced edit with JSON](https://confluence.atlassian.com/automation/advanced-field-editing-using-json-993924663.html) may be used with {{varAddedUsers}} and {{varRemovedUsers}}

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.


author: Mari Pervushina
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)This is working brilliant!  
Thank you so much!

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


author: Mari Pervushina
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

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](https://community.atlassian.com/t5/image/serverpage/image-id/339046i4361E1B8CB5D6D8A/image-size/large?v=v2&px=999 "2024-07-31_11-29-47.png")


author: Bill Sheboy
body: 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.


author: Mari Pervushina
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

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."


author: Bill Sheboy
body: 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.


author: Mari Pervushina
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

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


author: Mari Pervushina
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

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}},{{/}}{{/}}
      ] 
    }
}
```


author: Mari Pervushina
body: 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.

comments: author: Mari Pervushina
body: 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](https://community.atlassian.com/t5/image/serverpage/image-id/340328iF8AE70DE09AF250E/image-size/large?v=v2&px=999 "2024-08-06_17-21-27 (2).png")

![2024-08-06_17-24-03.png](https://community.atlassian.com/t5/image/serverpage/image-id/340276i3A9F3D8FF91351D5/image-size/large?v=v2&px=999 "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>


author: Bill Sheboy
body: Hi [@Mari Pervushina](/t5/user/viewprofilepage/user-id/4996235)

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


author: Mari Pervushina
body: Hello [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) , 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.


author: Bill Sheboy
body: 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.


author: Mari Pervushina
body: 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).png](https://community.atlassian.com/t5/image/serverpage/image-id/340325i71E40DDBEFA98F02/image-size/large?v=v2&px=999 "2024-08-06_20-23-47 (2).png")![2024-08-06_20-24-48 (2).png](https://community.atlassian.com/t5/image/serverpage/image-id/340326i67E5390DAE6A1C68/image-size/large?v=v2&px=999 "2024-08-06_20-24-48 (2).png")


author: Bill Sheboy
body: 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.


author: Mari Pervushina
body: Hello [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

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}})


author: Bill Sheboy
body: 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)>


author: Mari Pervushina
body: Super! Thank you very mash [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)


author: Mari Pervushina
body: 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](https://community.atlassian.com/t5/image/serverpage/image-id/338491i120099EA7BBE42CF/image-size/large?v=v2&px=999 "2024-07-29_12-45-21.png")

///

![2024-07-29_12-46-41.png](https://community.atlassian.com/t5/image/serverpage/image-id/338490i66935F078821485E/image-size/large?v=v2&px=999 "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](https://community.atlassian.com/t5/image/serverpage/image-id/338492iEC5901528BC7F71B/image-size/large?v=v2&px=999 "2024-07-29_12-52-35.png")

comments: author: Mari Pervushina
body: 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.


author: Bill Sheboy
body: Hi [@Mari Pervushina](/t5/user/viewprofilepage/user-id/4996235)

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


author: Trudy Claspill
body: Hello [@Mari Pervushina](/t5/user/viewprofilepage/user-id/4996235)

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.


author: Samuel Gatica
body: Hi [@Mari Pervushina](/t5/user/viewprofilepage/user-id/4996235)

Please check similar issue described [here](https://community.atlassian.com/t5/Jira-questions/fieldChange-fromString-and-fieldChange-toString-not-working/qaq-p/2446969)

Best regards

Sam

comments: author: Mari Pervushina
body: Hello [@Samuel Gatica](/t5/user/viewprofilepage/user-id/753028)

Thank you for you advice. I wrote my question in [here.](https://community.atlassian.com/t5/Jira-questions/fieldChange-fromString-and-fieldChange-toString-not-working/qaq-p/2446969#U2767999)

There is no answer to my question right now and [this](https://community.atlassian.com/t5/Jira-questions/fieldChange-fromString-and-fieldChange-toString-not-working/qaq-p/2446969#U2767999) topic about cloud instead my problem only for data center.


Tags: added

data-center

fieldchange

jira-data-center