Help

Re: Creating New Records with multiple field inputs via Scripting

Solved
Jump to Solution
2459 2
cancel
Showing results for 
Search instead for 
Did you mean: 
raechyl
6 - Interface Innovator
6 - Interface Innovator

I'm very new to scripting and my javascript knowledge from college is a very distant memory, so bear with me. I'm trying to create a script that will essentially generate a mini-form with three fields from my table that will create a new record when filled out.

I've been successful to a point but running into some issues. Code is below. Here are my questions:

  • Is my syntax correct to create one new record with multiple fields filled through user input?
  • How do I ensure the user input can be validated as a number for a currency column? My parseFloat() function is still causing errors (scripting block says it cannot create a record because it needs to be a number).
  • Both Payment Month and Payment Year are requiring objects, which I assume has to do with the fact that both fields are single select. This is important because I have functions and automations dependent on those being entered the same way every time. How can I alter my code to satisfy that requirement?

Thanks for any help!

 

// pick table from your base here
let deelTracker = base.getTable('Deel Tracker');

// prompt the user to enter new payments information
output.markdown('# Payment Estimate');
let Payment = await input.textAsync('Payment Estimate');
let Year = await input.textAsync('Payment Year');
let Month = await input.textAsync('Payment Month');

parseFloat(Payment);

// create record
await deelTracker.createRecordAsync(
    {
            'Payment Estimate': Payment,
            'Payment Month': Month,
            'Payment Year': Year,
    }
);

// confirm
output.text('Thank you!');
1 Solution

Accepted Solutions

Hi raechyl, try replacing the createRecordAsync function with this:

 

await deelTracker.createRecordAsync({
  'Payment Estimate': parseFloat(Payment),
  'Payment Month': {name: Month},
  'Payment Year': {name: Year},
})

I would recommend you look into the possibility of using buttonAsync instead of allowing your users to key in data themselves as typos will throw errors

 

See Solution in Thread

4 Replies 4

Hi raechyl, could you provide a screenshot of the relevant fields in the table as well, or, even better, a link to an example base with your extension already set up?

Each field type expects its own type of syntax, and the screenshot would be very helpful in determining said types

Having an example base would also save us the work of attempting to recreate your set up for testing and such

Thanks for responding!

Here's a link to the example: https://airtable.com/shrExSD0EDV1tTGcQ - let me know if that works for you, or if you need an actual invite sent. Below are a couple screenshots as well.

Thank you!

Screen Shot 2022-12-07 at 07.09.14.png

Screen Shot 2022-12-07 at 07.09.46.png

Hi raechyl, try replacing the createRecordAsync function with this:

 

await deelTracker.createRecordAsync({
  'Payment Estimate': parseFloat(Payment),
  'Payment Month': {name: Month},
  'Payment Year': {name: Year},
})

I would recommend you look into the possibility of using buttonAsync instead of allowing your users to key in data themselves as typos will throw errors

 

Thank you so much, works great!

I did make that edit with buttonsAsync too. Thanks!