In the last tutorial, I used a default template project and this is shown on the source code like this:
1 | table.select({maxRecords:3,view:'All tasks'}).firstPage(); |
If you use a grid view, see the next image:
then the source code for selection is this:
1 2 3 | table.select({ view: 'Grid tasks view' }).firstPage(); |
If you want to use javascript, it needs to have a good field name.
For example, use ‘EndDate‘ not ‘End Date’
I add more functions for use in this Grid task view and I create a new commit named 002 on my GitHub repo.
This is the source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | var Airtable = require('airtable'); // these can be see on the https://airtable.com/account and the var base = new Airtable({apiKey: 'your-key'}).base('your-app-id'); const table = base('Tasks') const getRecords = async () => { const records = await table.select({ view: 'Grid tasks view' }).firstPage(); console.log(records); } getRecords() const createRecord = async (fields) => { const createRecord = await table.create(fields) console.log(minifyRecord(createRecord)) } const minifyRecord = async (record) => { return { id: record.id, Task: record.fields.Task, Notes: record.fields.Notes, Status: record.fields.Status, Created: record.fields.Created, Ended: record.fields.Ended, EndDate: record.fields.EndDate // do not use field name like this: "End Date" } } createRecord ( { "Task": "another test", "Notes": "this is a javascript test create!", "Status": "Done", "Created": "2022-05-15", "Ended": "No", "EndDate": "2022-05-16" // do not use field name like this: "End Date" }) const getRecordsById = async (id) => { const record = await table.find(id) console.log("Get one record : ", record) } getRecordsById('your-id-record'); |