Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automations: how to use a variable inside a smart value list.get()

Eric Rodewald
Contributor
September 10, 2020

I am trying to pull a random item out of an array from a json webhook request. I've got the following done:

 

  1. create variables rand, listSize, newIndex
  2. run the webhook request, delay for response
  3. (works) set rand to:
    {{#=}}RANDOM(){{/}}
  4. (works) set listSize to:
    {{webhookResponse.body.size}}
  5. (works) set newIndex to:
    {{#=}}FLOOR({{listSize}} * {{rand}}){{/}}
  6. (works) verify this index is not a string by setting newIndex again to:
    {{newIndex.asNumber}}
  7. (fails) obtain by the new index with:
    {{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

1 answer

0 votes
Andy Heinzer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
June 21, 2018

Hi @Jean-François FORGET

I am afraid that the REST API endpoint that performs transitions, POST /rest/api/2/issue/{issueIdOrKey}/transitions is not actually expected to provide any other REST response other than the HTTP 204 code for a successful transition.  From that page:

Responses
  • STATUS 400
    If there is no transition specified.
  • STATUS 204
    Returned if the transition was successful.
  • STATUS 404
    The issue does not exist or the user does not have permission to view it

So although you can add comments during a transition, there has not been the expectation that the REST API would return to you the ID of that comment in that situation.

I understand if either your work-around are less than desirable, however when searching through the JRASERVER project on JAC I have not yet found another other previous requests for this particular functionality out of the transition REST response.  

If you like you could create a new suggestion issue in that project.   I would also recommend checking out the Implementation of New Features Policy.   I can't guarantee that this feature might be implemented some day, but providing a use case and an explanation of why this would be helpful to have can then at least serve as a place where other users can watch and vote on such a request. 

Suggest an answer

Log in or Sign up to answer