I am not posting a lot of screen shots or other visuals, because I felt this is a pretty straightforward question that has nothing to do with workflows or the like. Please let me know if I'm mistaken after reading, always willing to admit I was wrong :)
I have the following fields:
I have an automation rule that updates the Index field, incrementing it by 1 as issues are transitioned from one approval step to the next. That is working just fine.
The problem is occurring when I try to access a value in the text field via an index number. I have tried creating a variable called Index:
{{issue.customfield_11195.asNumber.round}}
to ensure that the value is an integer and not a decimal, etc. I then was trying to use that variable like so:
{{issue.customfield_11163.split(",").get(Index).trim}}
to access the value at the correct index position.
I have tried tweaking the statement in multiple way. My overarching question is:
Is it possible to use the .get(n) statement with a variable being the value of n?
Howdy,
Directly NO, it is not possible to use a smart value variable (like {{Index}}) as the index parameter in the .get(n) method within Jira automation rules, the feature request for this can be seen at the link below MAKE SURE TO ADD A VOTE:
However I was playing around with this a bit and pretty sure property entity is gonna be your friend here, a little more complex but a decent workaround.
To store the index value in an issue entity property (in JSON format), then reference that property's value within the .get() method. Entity properties act as a temporary storage layer that allows the value to be resolved correctly during evaluation. Here's how to implement it step by step, tailored to your example (assuming Index is derived from {{issue.customfield_11195.asNumber.round}} and is guaranteed to be a non-negative integer within the bounds of your split list):
{{issue.customfield_11163.split(",").get(issue.properties.tempIndex).trim}}
This approach looks like it should work reliably for dynamic indices, even in branches or iterators, as long as the property is set in the same rule execution. If your lists are very long or the index comes from complex math (like random selection), you can extend it by storing multiple values in a single JSON property (e.g., {"index1": {{Index}}, "index2": {{AnotherVar}}}) and accessing them separately as well as adding in delay and re-fetch actions between calls to space it out and avoid race condition scenarios.
Hope this helps ya :)
peace out,
- The Earl
Hello @john_monteith
I don't have a solution, but I wanted to share what I tried.
My first thought was that the problem is all variables are stored as strings, and get() couldn't cope with a string as its parameter
You may be assigning an integer value to your variable named Index, but when you then use Index it is evaluated as a string.
So my suggestion was going to be to try this:
{{issue.customfield_11163.split(",").get(Index.asNumber).trim}}
But I tested that out myself using Log actions to print out values:
{{issue.Summary}}
{{Index}}
{{Index.asNumber}}
{{issue.Summary.split(",").get(1)}}
{{issue.Summary.split(",").get(Index.asNumber)}}
The values that printed were:
a, b, c
1
1
b
<nothing>
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.