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}} .
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:
From String values: {{#changelog.your Custom Field From The Trigger}}{{fromString}}{{/}}
From values: {{#changelog.your Custom Field From The Trigger}}{{from}}{{/}}
To String values: {{#changelog.your Custom Field From The Trigger}}{{toString}}{{/}}
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Нere are two more field changes. As you can see, the row is inserted according to alphabetical order.
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! 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Did I understand correctly what needs to be done?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
{{#changelog.your Custom Field From The Trigger}}{{fromString}}{{/}}
{{varFromStringData.remove("[").remove("]").replace(", ",",")}}
({{varFromUserNames.replace(",","|")}})
{{#changelog.your Custom Field From The Trigger}}{{toString}}{{/}}
{{varToStringData.remove("[").remove("]").replace(", ",",")}}
({{varToUserNames.replace(",","|")}})
{{varToUserNames.replaceAll(varRegExFromUsers,"").split(",").match("(.++)").join(",")}}
{{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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill SheboyThis is working brilliant!
Thank you so much!
I'll figure out how it works, "split and join" a great solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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}},{{/}}{{/}}
]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First I try to use custom data. And I have no idea why this doesn't work?
I used this article
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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}})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
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.
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.
///
And the variable StudentName = {{fieldChange.toString.diff(fieldChange.fromString)}} returns Empty, see log bellow.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.