Looking up a hashtable with a table column field value

Expected Outcome: By saving some data retrieved from an API ( I created) endpoint request as a hashtable in a Temporary State variable, I can display the specific outputs for the relevant row in a table element custom column, using another value on the table (in this case a field name of id) as the "lookup" on the hashtable to retrieve and display the relevant value on that custom column and for that specific row.

Current outcome: attempting to use the i variable to lookup the temporary state variable just results in an undefined output, even though the id column has values generated for each row.

eg:
{{i.id}} results in an 'undefined' preview.

I have console.log'd the temporary state variable, and it looks like the hashtable is setup as expected, my issue seems to struggling with the correct syntax for how to reference a column value for a given row on the table (populated with table data upon a successful API request)

Something like this:
sample id value: UCHZZo1h1cI1vg4I9g2RqOUQ
{{ JSON.stringify(channel.value[i.id].contact[0]) }}

However, that just results in an undefined

Note: this is related to the community post here from a while back as well: link

Also maybe @Kabirdas could help? :pray:

ok, so I temporarily solved the issue by just changing the hashtable structure to something 'index' driven, using the index of each row from the table as opposed to a custom (and unique) string id. so for example:

{
   0:{
   "details": ["item1","item2"]
   }
}

Where the 0 key maps to the i index variable of the table row in question.

It still would be great to know if I can somehow reference existing table column/field values in order to lookup a hashmap in the temporary state.

This feels like it would be more robust to me (ie less risk of collisions and confusing with an integer index?) so I would appreciate any thoughts here!

Hey @andymac! Happy to help with this. Would you mind sharing what your original data structure looks like?

1 Like

@victoria, sure!

My original temporary state was initialized as an empty object {} and then using the setIn method, I append nested objects that looked like this:

{
// key is the youtube unique channel id
    "UC_i3GAnlCgaK-id6pPCOPzQ":{
          "contact":[
          {"type":"email", "value":"some_creator@email.com"}
          ]
    }
}

However, when I tried to 'lookup' the temporary state using the id (this is the channel id value that is returned from my third party endpoint API that the table is querying) column on the relevant table for a custom field that I was attempting to display this information on, I tried several syntatical variations of i.id (eg, me attempting to use that specific table row id value to lookup the hashtable) however, i.id kept returning undefined so I just used the i index instead for now which isn't really ideal because imo it doesn't really scale or map nicely if and when the i index on the table changes or more data is appended to the state in the future

Hey again @andymac!

The i variable is defined within a table and any queries/scripts that the table triggers directly and nowhere else.

If you have a custom column and you want to set it to some value in the table directly, you can set the value to something like {{currentRow.id}} or {{currentRow.sales - currentRow.cost}}

You can also do something like {{table1.data[i].id}} or {{table1.data[i].sales - table1.data[i].cost}} in that custom column.

Does this help at all? I'm afraid I'm still a bit unclear about your current setup, but happy to hop on a call with you sometime to get this sorted if you're blocked anywhere! :slight_smile:

1 Like

Thanks @victoria I tested the {{currentRow.id}} approach with some test data in a temporary state object and your approach is the solution I was looking for, so marking your reply as the solution

As an aside, I thought I had attempted using currentRow keyword, but it's entirely possible I garbled the syntax when I had.

For posterity, my sample data looked something like this: (named testChannel)

{
	"UCHZZo1h1cI1vg4I9g2RqOUQ":{
	"contact":"hello@UCHZZo1h1cI1vg4I9g2RqOUQ"
	},
	"UCMZqYzRTqa23lKigfOZ_2_A":{
	"contact":"hello@UCMZqYzRTqa23lKigfOZ_2_A"
	},
	"UCWvRJ6lEwLW9lY3J0Ao1tGA":{
	"contact":"hello@UCWvRJ6lEwLW9lY3J0Ao1tGA"
	}
}

And I retrieved that contact kvp in a specific custom field on my table with this custom field formula:
{{testChannel.value[currentRow.id]?.contact}}

Hey @andymac! So glad to hear it's working for you now.

I tested a similar setup with your demo data and it seems to be working as you had written! The only difference being that I'm using the new table so the currentRow property is called currentSourceRow instead :slight_smile:

1 Like