Call putItem on a DynamoDB Resource from inside a javascript block

I have a DynamoDB resource in my form. I can call putItem indiividually through the WYSIWYG interface and wired that up. How do I access the putItem method dynamically from inside Javascript code block.

Hi @elischleifer, happy to help! Can you provide a bit more context on the use case and where the JS code block is being run? Are you attempting to run the putItem method from the query editor or somewhere else in a Retool App?

I have a textfield that I want users to enter a comma separated list of values into. I then on button click run JS code to split the input and then I want to post putItem for each entry in my dynamic db table

Sure! There are a few ways you can do this. If you have a list of values separated by commas, you can run a JS query on the component to split them by commas. Once you separate these values, you can pass them into another query that will insert each value into your resource! I've created a sample app to demonstrate this on a Postgres DB. You should be able to run very similar code but use the putItem instead of insert.

The additionalScope object allows us to pass in values to the query that we would like to use on the Insert Query. In this case, I pass in each name as firstName. Then, in the query that runs the insert, we use the {{firstName}} as our value for insert. Please note that this value will show as undefined until the the query is run.

I've attached a few screenshots below, please take a look and see if they make sense. Let me know if you have any questions!

Screen Shot 2021-10-06 at 5.54.17 PM.png Screen Shot 2021-10-06 at 6.02.56 PM.png Screen Shot 2021-10-06 at 6.03.03 PM.png