Query Airtable data from List Detail through Custom Code Block

Hello community,

I am generating a list of record, thanks to a Airtable base.

In the Detail page (from the list), I wish to call, through a Custom Code Block, some additional data present in the Airtable that is the data source of the Detail page.

I tried with a lot of things, but I cannot call the record…
Please help!

@acjnas do you know if a custom code solution exists for this?

1 Like

Hey @Jjenglert !

Hope you are doing great :sunny:

Feel free to share this code

I had the need to populate the FAQ softr block with dynamic data from airtable

<script>
function waitForRecords() {
  return new Promise((resolve) => {
    const checkRecords = setInterval(() => {
      if (window.records !== undefined) {
        clearInterval(checkRecords);
        resolve(window.records);
      }
    }, 1000);
  });
}

function populateFAQ(records) {
  const record = records[Object.keys(records)[0]].record.fields;

  const setTextContent = (id, field) => {
    const element = document.getElementById(id);
    if (element && record[field]) {
      element.innerText = record[field];
    }
  };

  setTextContent("faqq1", 'Q1');
  setTextContent("faqa1", 'A1');
    setTextContent("thecategory-name", 'Program category');
  setTextContent("thecategory-link", 'Category url');
}

waitForRecords().then(populateFAQ);
</script>

Let me know if you need anything else my friend.

2 Likes

Thanks for your prompt answers guys!

For more precision, my Airtable record, connected as Data Source for the List Detail Page is called “Workflows”, and I’m trying to call the fields with the header being called “inputMethod”