Pass airtable data to custom block code using fillout form

Hi team. Could you help get data from specific fields on airtable to a custom block?

I am using a code to recognize airtable user ID and pass to a fillout form.

<div style="width:100%;height:500px;" data-fillout-id="wtjH1tfWmCus" data-fillout-embed-type="standard" data-fillout-inherit-parameters data-fillout-dynamic-resize></div>
<script>
document.querySelectorAll("[data-fillout-id]:not([data-fillout-id=\"\"])").forEach((target) => {
    if (window.logged_in_user && window.logged_in_user.softr_user_email) {
        target.setAttribute("data-email", window.logged_in_user.softr_user_email);
        target.setAttribute("data-name", window.logged_in_user.softr_user_full_name);
        target.setAttribute("data-id", window.logged_in_user.airtable_record_id);

    }
});
</script>
<script src="https://server.fillout.com/embed/v1/"></script>

Now I need to get data from a other airtable fields. For example the field status under “contacts” table on airtable

Also I need to get a record ID from a detailed page where the form is embed. There is a list detail block in the same page I have the custom code block. The ID I need is called “ID evento” under “eventos” table" . is the same ID from the Page URL as we are in a detailed page.

Can you help me finish this code?

thanks

To display data from other table than ‘users’ , simply add the table to your page and map the needed values in this new block. Then hide it with css. Now the values for that record can be accesed from the window.records object. And then can be placed anywhere on your page, or can be passed as parameters to your fillout form.

Also accesing the record id in your url can be done with some code like:

<script>
        let pageUrl = new URL(window.location.href);

        let id = pageUrl.searchParams.get("recordId");

        let filloutUrl = 'https://form.fillout.com/t/xxxxxxxxus?' + 'id=' + id;

        if(window['logged_in_user'] && window['logged_in_user']['softr_user_email']) {
            filloutUrl = filloutUrl + '&email=' + window['logged_in_user']['softr_user_email'];
            filloutUrl = filloutUrl + '&name=' + window['logged_in_user']['softr_user_full_name'];
            filloutUrl = filloutUrl + '&userid=' + window['logged_in_user']['airtable_record_id'];        }

        document.write('<iframe src="' + filloutUrl + '" width="100%" height="1200px" frameborder="0" marginheight="0" marginwidth="0" title="Actualizar recibo" id = "editarrecibo" scrolling="no"></iframe>');
    </script>

Thanks for replying Jonathan.

I am not sure how to use window.records object

If the record ID i need is in the table called “eventos” and the filed for this record ID is called “ID evento” how should the code be?

Ok, I thought that record id you needed it was listed in the url.

First you must have listed on the details page the value that you expect to grab.
It can be hidden with css but it must rendered so we can access it.

Then you can try this:

<script>
// Get record field values to map them into section 
    const wait = setInterval(function () {
        if (window.records !== undefined) {
            clearInterval(wait);
            document.getElementById("service-name").innerText = window.records[Object.keys(window.records)[0]].record.fields['Service name'];
            document.getElementById("service-description").innerText = window.records[Object.keys(window.records)[0]].record.fields['Service description'];           
        }
    },1000)

</script>

<!--Now lets show the dynamic values into page -->

<div id= 'service-name'></div>
<div id= 'service-description'></div>

Thanks Janathan. Now i cannot understand anything lol. SOrry, I am not technical.

The code below is what is working right now. I am retrieving user id , email and name. I need to retrieve the record ID from table (eventos). This ID is also in the URL because is a detailed list.

<div style="width:100%;height:500px;" data-fillout-id="gaAEu9Vb48us" data-fillout-embed-type="standard" data-fillout-inherit-parameters data-fillout-dynamic-resize></div>
<script>
document.querySelectorAll("[data-fillout-id]:not([data-fillout-id=\"\"])").forEach((target) => {
    if (window.logged_in_user && window.logged_in_user.softr_user_email) {
        target.setAttribute("data-email", window.logged_in_user.softr_user_email);
        target.setAttribute("data-name", window.logged_in_user.softr_user_full_name);
        target.setAttribute("data-id", window.logged_in_user.airtable_record_id);

    }
});
</script>
<script src="https://server.fillout.com/embed/v1/"></script>```

HI Jonathan, I have replaced my code with yours abd now all data I need is retrieving. thanks a lot! Now I am able to get any variable from the user table and also the page URL Id

    <script>
        let pageUrl = new URL(window.location.href);

        let id = pageUrl.searchParams.get("recordId");

        let filloutUrl = 'https://form.fillout.com/t/gaAEu9Vb48us?' + 'id=' + id;

        if(window['logged_in_user'] && window['logged_in_user']['softr_user_email']) {
            filloutUrl = filloutUrl + '&email=' + window['logged_in_user']['softr_user_email'];
            filloutUrl = filloutUrl + '&name=' + window['logged_in_user']['softr_user_full_name'];
            filloutUrl = filloutUrl + '&IDuser=' + window['logged_in_user']['airtable_record_id'];
            filloutUrl = filloutUrl + '&Status=' + window['logged_in_user']['Status'];    }

        document.write('<iframe src="' + filloutUrl + '" width="100%" height="1200px" frameborder="0" marginheight="0" marginwidth="0" title="Actualizar recibo" id = "editarrecibo" scrolling="no"></iframe>');
    </script>```

Hey !

I am very happy for you ! I am glad you make it work, I know how it feels!

I have been working with fillout forms almost since day one, and they do integrate very neat into my softr projects.

The guys at fillout are fearless, they put together a remarkable tool when it comes to form handling.

La mejor de las suertes para este y todos tus proyectos en softr. Si me necesitas estamos a la orden, para trabajo dedicado o ayuda elemental.
Mi experticio es mas notable con airtable/softr/fillout/make

Hi Jonathan, do you use whatsApp? or whats your email?