Pass User Variable in to Custom Code Block

Is it possible to pass along a variable from the current user in to a embedded code block?

In the Airtable record for each user, we have a code that is used to call up a particular form for each user. We’d like be able to load that particular field value in the embed code.

Search for window.records in the forum, I think IDuser = window['logged_in_user']['airtable_record_id'];could work with Js, to adapt to any field from airtable

Yes, that’s right.

To add on: how to get this parameter into the embed block will vary depending on what you are embedding. If you can say more about exactly what you’re trying to embed, we can help with specifics of how to do it.

@dcoletta Thanks for the help! Here’s the use case for the variable that I’d like to get out of Airtable and have that in this code snippet (puts a Paperform inline in the page):

<div data-paperform-id="companah-joco" data-takeover="1"></div><script>(function() { var script = document.createElement('script'); script.src = "https://paperform.co/__embed.min.js";document.body.appendChild(script); })()</script>

The first DIV attribute is the id for the form, in this case “companah-joco”. In this case, the variable item would be “joco”, and that is what I would like to be able to pull from the user record in Airtable.

I’m getting the following error trying to get a field from a userID

Uncaught TypeError: Cannot read properties of undefined (reading ‘recGM6aA5T4GYUQFb’)

I’m able to get the user ID but not any fields related to the user in airtable. Does this have to do with the new security settings?

I’m trying to use the user airtable field to store states that I can access to display custom content. FOr example instead of constantly sellecting a project, a current project variable is set with the corresponding ID so the user will see that related information without having to navigate to the project list and then select a project to go to the project details page.

See script below:

<script> IDuser = window['logged_in_user']['airtable_record_id'] console.log(IDuser) designOption = window.records[IDuser].record.fields['currentDesignOptionRecordID'] console.log(designOption) </script>

Hello @bfortunato ,

From what I can tell, it looks like this will fix your issue? You just need to directly grab currentDesignOptionRecordID from the Window[‘logged_in_user’]. Hope this helps!

<script> 
designOption = window['logged_in_user']['currentDesignOptionRecordID'] 
console.log(designOption) 
</script>

Thanks,
Paul