HubDB Table/CSV file imports

Highlighted
New Contributor

I created a rates page on our website and have a HubDB table pulling the data into it. The rates are updated daily. I thought that I could just upload and replace the CSV file onto the HubDB table and it would be good to go but when I upload the new file, the ID numbers are updated within the hubdb table as well - which makes a disconnect to the rates page.

Is there another way to accomplish this?

Reply
0 Upvotes
3 Replies 3
Highlighted
New Member

Are you trying to access the rows by row id? Don't you have any other fields to look up the price?  

Reply
0 Upvotes
Highlighted
HubSpot Employee

Hi @kferraro ! I took a look at this and I made an example custom module in your portal that shows how this might be accomplished (I removed your HubID, so you will have to substitute it in for the Xs): https://app.hubspot.com/design-manager/XXXXXX/modules/21778068387

I copied the HTML for the table into a custom module. In the custom module, I added a HubDB field that allows you to select which HubDB field to use in the module. Next, I added a bit of HubL at the top of the custom module to copy all of the row IDs for the selected table to an array/sequence:

  {% set row_array = [] %}
  {% for row in hubdb_table_rows(module.hubdbtable_field) %}
    {{ row_array.append( row.hs_id ) }}  
  {% endfor %}

Then, in the area of the table that used to reference the values by row ID, I changed the syntax to be more like this:

<p style="text-align: center; font-size: 15px;">{{ hubdb_table_row( module.hubdbtable_field, row_array[0]).rate }}%</p>

so now we are referencing the product for the row at index 0 in the array we just made {{ hubdb_table_row( module.hubdbtable_field, row_array[0]).product }} instead of before, where you were referencing specific row numbers {{ hubdb_table_row( 1053882, 21504528746).product }} I did hard code in the row references so the other rows are pulling row_array[1] and row_array[2] , but this should work for your use case, which is that when importing data, the row ids change

Reply
0 Upvotes
Highlighted
New Contributor

Thank you so much @adanielson! A good way to end the week successfully Smiley Wink 

I appreciate your help!

Reply
0 Upvotes