ListView component value in rest API

I'm trying to create a ticket in Zendesk using the REST Api integration.
Everything seems working properly, but I've problems retrieving the value from the ListView component.

  "ticket": {        
    "subject": "xxxx {{[i]}}",         
    "comment": {             
      "html_body": "xxx"
      "requester": "{{[i]}}",
        "status": "solved"

The strange part is that using "Preview" it works properly.
Clicking on "Run" instead name is "undefined" and probably the email too, since it takes the one used for the connection with Zendesk.

Any idea?


Hey @number15!

It looks like you're using the i variable in your query, which isn't actually defined until the List View component passes it in. The list view passes i in when the query gets triggered from somewhere in the list view (e.g. a button in the list view).

Preview works because i, when undefined/not passed in yet, uses a default value of 0 only in the preview.

So basically, clicking Run on a query that uses i will never work. You'll need to trigger the query from the list view!

Let me know if that clears anything up or if you still have any other questions :slight_smile:

Thanks @victoria, now is clear.

My problem is the following: i've a button in the listview that trigger a query to update the value.
On success, this query runs the API Zendesk request to create the ticket.

So I solved the issue triggering also the API request clicking on the button, but not sure it's the best way to do it.
Now it's more a theoretical question: in this case the first query will never fail, so it's not a big deal, but is there any way to use the i variable in a different way?

Ah so you're essentially trying to pass the i variable into two queries, but you'd only like to run the second query on success of the first query.

Great question!

There are a few ways to do this, but I'd probably do something like this:

1. Button's event handler runs a script to trigger both queries. It triggers query1 first then on success, triggers query2. In query2, it passes in the i variable as additionalScope. Here's a community post walking through additionalScope and here's the code I used:

query1.trigger({onSuccess:() => query2.trigger({additionalScope: {i_var: i} })})

2. query1 stays the same, but query2 now needs to reference i_var (this is a random name I gave our additionalScope variable in the event handler. You can name it whatever you'd like!) instead of just i like so:

Let me know if you have any questions about this!

query1.trigger() is not working.
It seems that I need to use also here the additional_scope for the i variant like this:

This works:

query1.trigger({additionalScope: {i: i}})

query1 is something like:

SET status_id = 5
WHERE id = {{[i]}}

Ah, yup. So glad to hear it's working for you now! :clap:

Yes, thanks.

Additional question: :slightly_smiling_face:
If the second query needs to run for specific values only, how I can do with this new way?

The value is like: dropdown[i].value
I was thinking to disable the second query based on dropdown value, but I'm not find how to do it.

This is the complete script:

query1.trigger({additionalScope: {i: i}, onSuccess:() => query2.trigger({additionalScope: {i_var: i, reason: dropdown[i].value} })})

I see correctly the value in the additionalScope in the console

additionalScope: {i_var: 0, reason: "bad"}
i_var: 0
reason: "bad"

but not finding how to use it ({{reason}} is empty :upside_down_face: )

Good question!

Would something like this in your event handler work for you?

query1.trigger({onSuccess: function() { 
  if (numberInput1[i].value < 200) {
    additionalScope: {i_var: i} 

Or for your code specifically, maybe something like this to only run query2 if the dropdown is NOT 'bad':

query1.trigger({additionalScope: {i:i}, onSuccess: function() { 
  if (dropdown[i].value != 'bad') {
    additionalScope: {i_var: i} 

Great, it works smooth now!

But... Why I can't use {{[i_var]}} in query2 success notification?

Like Sent email to {{[i_var]}} is empty.

The value works in the ticket itself, but not in the notification.

@victoria we've another app where the component that needs to send data to rest API is a listView inside another listView.
To print it the format is like: eval([0])[ri[0]][i] }}

How should be the script to send the correct ri and i?


Hmm this is started to get a bit more difficult to understand without seeing your actual setup :sweat_smile: What timezone are you in? Do you think you’d be interested in stopping by Community Office hours sometime? We have a couple times suitable for EST/PST and some times suitable for APAC as well

If not, would you mind sharing a few more screenshots of your current data structure?

@victoria I know, sorry about that :slightly_frowning_face:
I'm CET.
The problem is that we've strictly privacy policy, so not so easy to share complete things.

In some particular case like this, as business plan user, is it possible to shoot an email directly to support? If yes, which is the email?

@victoria thanks!

Btw I think I found how to do it, simply using in the additional scope the value itself instead of sending the i.

So the run scripts are now like:

query1.trigger({additionalScope: {i: i}, onSuccess: function() {
  if (dropdown[i].value == '2') {  
    additionalScope: {
    additionalScope: {
      a_1: eval([0])[ri[0]][i],
      b_2: eval([0])[ri[0]][i]      

And in the queries I can use directly the variable like {{a}} or {{a_1}}.

Do you see any downside doing this?

No downside, that all looks great and I'm glad you round something that works for you! I've shared this post with a couple other users looking to do the same thing, so thank you for helping document this set up :slight_smile:

1 Like