I have a rule that should update a multi-user field without overwriting existing users from a previous rule run.
When searching for how to accomplish this, I came across this post in the documentation:
Update values in a multiuser picker field using automation in Jira Cloud
Here is my rule with the Additional fields JSON code, which I copied from the article and then substituted my field to update, as well as tried to use a created variable to get the existing user in that field. I do not understand the warning/error message I am getting, and do not understand why this shouldn't work correctly.
Hi @Danno
First, please post an image of your complete rule (in a single continuous image) for more context.
Next, there are definite typos in that article you linked to, and so I recommend creating the dynamic JSON expression in a text editor to check / match up the syntax for bracketing.
Finally, that error seems like an internal, editor check due to a copied rule component that did not properly update the internal component ID values. The fix may end up being to abandon your edits with Return to Rules and try the edit again.
Kind regards,
Bill
@Bill Sheboy thank you for the quick reply, but before I bore you with the rest of the rule 😜, it is just a series of 4 IF-Else checks to get the needed user id to add to the multi-user field. The portion of the rule in question is the screenshot of step where I am trying to get the rule to add the 2nd user.
Since you mentioned the define typos in the article, can you point me to a useful text editor to do the check / match up the syntax for bracketing? I do struggle with counting them and keeping track of open and close pairs.
Can you further explain the rule component theory? Are you saying that a rule step/section is a component and that that section/component could now have a corrupted/different id than when it was first created? If so, I think your suggestion might be the fix. I will try that right away.
Lastly, I have added the screenshot for the section where I create the GetApprovers variable to collect the existing ids in the variable and then log what is found to keep tabs on the rule as I go. I also included the audit log showing that it picks up the id as expected.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Let's start with your rule...
The create variable action is saving the value from the field, which appears to be a multiple-selection user one. The way you are doing that, it uses the default attribute (i.e., accountId) and uses the default join with a comma followed by a space. But your split() only uses a comma (as does the article's example). In your case, this will case a leading space between the values, such as:
123, 456, 789
And so the two possible fixes are:
Please only do one of those options.
For checking the syntax, you could use a free editor such as NotePad++ or if you happen to have your favorite code IDE open, just use an empty JSON file to perform a quick check.
Regarding the rule component ID values: yes, I believe an ID got corrupted.
Each piece of a rule has one or more components for the trigger, actions, branches and conditions. (The if / else block is special as it adds an extra component to manage the block.) And each component has a unique ID to help the rule manage the processing. Occasionally rules get "glitched" when they are updated / published too many times. The fix is to re-create them.
Also, there was an update in the last week (which I have not tested yet) to allow copy / delete / export of rules while editing them. I wonder if something got bent / broken with that one.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy Lots of good info to work through, including the Cloud updates link.
I ended up deleting the original rule I started with and created a new one with just the create variable and a log action first, and I am now working on a single test and edit to work through your suggestions to fix the JSON part.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy last update for now. For context, here is what I have for now.
I've tested the new rule and I now get useful error messaging, although it is not entirely accurate. I did get something similar when I was trying to remove users in an earlier iteration. I was informed that Remove wasn't available for this type of field. That said I've tried add, set and edit to no avail.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My apologies if I was unclear as it appears you my suggestions in the wrong places.
Let's confirm what you are trying to accomplish. Which one is it?
#1) When trying to just add the {{initiator}} the JSON only needs this:
{
"update": {
"customfield_11551": [
{
"add": {
"id": "{{initiator.accountId}}"
}
}
]
}
}
#2) When trying to add a list of values delimited by commas only, please use this:
{
"update": {
"customfield_11551":[
{{#GetApprovers.split(",")}}
{
"add": {
"id": "{{.}}"
}
}
{{^last}},{{/}}
{{/}}
]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy no apologies are necessary. You've been very helpful in improving my understanding of this.
#1. is what I was after and your code worked as expected.
I have no idea why I didn't come across a code example like your fix.
My original idea was to start with a group of users pre-populated and then remove them as they completed an approval. Some of the documentation I found was for the Data Center software that showed that it could be done using the various commands of add, edit, and remove, but also had the disclaimer that it wouldn't work in the Cloud. In my haste, I tried it anyway and got a direct error code that the remove command was not applicable.
I decided to change this to add the approvers as they completed it, and got very mixed messages about how to add a user without overwriting the existing users already populated in the field. That's when I reached out.
Again, thank you for your help. I learned a lot.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome; I am glad to learn it is working! Please consider marking this question as "answered" to help others with a similar need find solutions faster. Thanks!
Regarding examples from Jira Data Center (and from bot-generated suggestions), the automation features of Cloud, Server, and Data Center are different, with Cloud having the most advanced ones. Thus what may work for one Jira version will not work for others. And, bots cannot see your specific configuration when they guess, so I recommend not using them without a high degree of caution.
The examples you describe were required in the past to remove a single value from some types of multiple-selection fields: gather the current list, use list functions to remove one value, and then re-add all the remaining ones with JSON.
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.