I have an automation that examines the Labels field values and builds a string based on found labels (ultimately, I want to remove those labels). The first challenge is that if I find fewer labels than the total number of labels, I end up with a trailing comma at the end of my string that I want to remove.
So, I try to remove the last character from my string, as follows:
Smart Value: teamLabels (examines the labels field and builds up a string based on found values):
{{#labels}}{{#if(startsWith("team/"))}}{"remove": "{{.}}"}{{^last}} ,{{/}}{{/}}{{/}}
Problem is that this can leave a trailing comma if there are additional labels. So, I try to remove it.
Smart Value: teamLen (gets the length of teamLabels - 1)
{{#=}}{{teamLabels.length()}}-1{{/}}
Smart Value: teamLabelsTrim (returns teamLabels with the last char removed)
{{teamLabels.left(teamLen)}}
I have tried multiple variations of the formula for teamLabelsTrim and either Automations can't parse it, or teamLabelsTrim comes back empty. I verified teamLabels and teamLen have appropriate values.
When I tested your first smart value expression for removing the teamLabels it did not leave any trailing commas for several test scenarios.
Would you please post an example where it did leaving a trailing comma?
Also I recommend writing that expression directly to the audit log as that may confirm if the problem is the input (i.e., labels), the smart value expression, the JSON into which you are inserting that, or something else. Without seeing your entire rule it is difficult to know.
Kind regards,
Bill
Given these values in the labels field:
escalation
non-team-label
team/team-a
This smart variable:
{{#labels}}{{#if(startsWith("team/"))}}{"remove": "{{.}}"}{{^last}} ,{{/}}{{/}}{{/}}
Results in this string value:
{"remove": "team/team-a"} ,{"remove": "team/team-b"} ,{"remove": "team/team-z"} ,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First thing, thanks for that information as I was able to reproduce the symptom you are seeing!
Next thing: I recommend submitting a ticket to the Atlassian support team for this one. There appears to be some remaining thing/object after the smart value, list filter, perhaps caused by this syntax using the iterator with an implied target for startsWith(), leading to the extra comma. I also tried delimiters other than the slash, and those had the same symptom. You appear to be the site admin for a paid Jira license level, and so you can submit that ticket here: https://support.atlassian.com/contact/#/ Once you hear back from them, please post what they say to benefit the community.
Okay, now for a work-around...
One approach is to remove whatever that stray thing/object is, without the need to do the math on the text-length. One way is to first save the results in a variable, and then use replaceAll() to only get what you want. For example:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The behavior is expected. I am looping over the labels and building a string based on matched values found. The {{^last}} means that, if I haven't reached the last element in the labels, then add a comma. If there are extra labels that don't match what I'm looking for, those are skipped and I'm left with the dangling comma.
Example, assuming labels is:
"team/team_a", "not_my_team"
First label found is team/team_a, append to the teamLabels string:
"remove": "team_a"
Last label? False, so append a comma:
" ,"
Next label found is "not_my_team", skip.
Last label? True, so skip adding the comma.
Result:
"remove": "team_a",
I'll give the workaround a whirl and report back.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I understand how the last works. With your iterator structure, the use of last is placed such that there should not be a trailing comma (due to the filter)...unless there is something present.
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 am glad to learn that helped. When I wrote that one, I just did some quick testing around your scenario. Please try the different cases you expect to confirm it works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you try for the teamLabels.left this instead
Smart Value: teamLabels
{{#labels}}{{#if(startsWith("team/"))}}{"remove": "{{.}}"}{{^last}} ,{{/}}{{/}}{{/}}
Smart Value: teamLen
{{teamLabels.length - 1}}
Smart Value: teamLabelsTrim
{{teamLabels.substring(0, teamLen)}}
It may not work but that's all i got
Best,
Clark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Given the smartValue teamLabels result:
{"remove": "team/team-a"} ,{"remove": "team/team-b"} ,{"remove": "team/team-z"} ,
This smart variable (teamLen):
{{teamLabels.length - 1}}
Results in an empty value.
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.