Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×I am trying to pull a random item out of an array from a json webhook request. I've got the following done:
{{#=}}RANDOM(){{/}}
{{webhookResponse.body.size}}
{{#=}}FLOOR({{listSize}} * {{rand}}){{/}}
{{newIndex.asNumber}}
{{webhookResponse.body.get(newIndex)}
Unfortunately, this doesn't work at all. I've tried variations like:
{{webhookResponse.body.get({{newIndex}})}}
When I just use a raw literal number, it works fine. e.g.,
{{webhookResponse.body.get(0)}}
Not really helpful if I'm building a random function, basically.
Am I missing some nuance about the syntax here? Thanks
Has this been resolved? Im having the same problems
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just spent a weekend trying to get something done with this. Such a stupid limitation!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
See the answer here where they first generate the index as a smartValue, then set that as an issueProperty, which is accessed within the .get( ) function.
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.
Hi Eric,
Thank you for your patience waiting on an answer for your problem. We have been looking into it, and trying to find a solution for your use case. Unfortunately, the current implementation of custom variables only allows for storing of values as strings. So 'newIndex' in your rule is always evaluated as a string, regardless of its original type. This is a limitation we are aware of, and is something we are working towards solving.
Within that limitation, I do not believe there is a way for you to do what you are wanting. I have raised this internally with the team, and we will hopefully be able to provide the functionality you are wanting in the near future.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for responding. I started to realize that and abandoned this technique, but even if there was a "JSON.parse()"-esque function that could be used to parse and obtain a value, it could be used inline in a way that doesn't require persisting it as an object.
For what it's worth, I made a naive version of this where I store a number of strings in variables and then used a random function to traverse through several conditionals to select a value.
Looking forward to seeing what you guys come up with for a better long term solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sam Harding
Is there any update on this limitation?
I ran into the similar situation where I have two separate lists with the same length and there is a need to get the item of the second list based on the current index of the first list. Hence I need a function where I get pass a variable in the get() function.
Thanks,
Priska
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you tried the following?
{{webhookResponse.body.get(newIndex.asNumber)}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi. Gordon.
It does not work either. By any reason the 'get' function only can be used with fixed numbers. I have the same issue.
Actually, in no function with numeric parameters (charAt, left, etc.) you can use a variable, even with 'asNumer' sufix.
Smartvalues is a real pain for developers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Smartvalues is a real pain for developers.
There are few statements truer than this.
The inconsistency in the conditions under which different methods/expressions operate, combined with the limitations on using different data structures...
It feels like every single possible permutation of expressions has to be tested individually to determine if it will be interpreted correctly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just wasted a day of my life to get an list index to be stored inside a variable... only to find out, I can't set FixVersion with a certain version by accessing the list of versions with the help of my variable.
I hate days like this 🙁
Failed to get value for issue.project.versions.get({{myindex: {{issue.project.versions.get({{myindex}})}}
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.