Task: Read from Airtable
In this task, we will modify code in Google Apps Script to read data from Airtable
1. In the Google Apps Script editor, open the "app.gs" file.
2. Modify the "get_tasks" function to appear as follows:
function get_tasks(){const data = get_airtable(base_id,api_key,"Task","",["sequence","group","task","details"])console.log(data)}
3. Run the function to see the data that comes back from Airtable
4. Replace "console.log(data)" with the following code to return the data or an error message generated by Airtable:
if(data.error){return {status:"failure",message:data.error.message}}else{return {status:"success",records:data}}
5. Run the "test_task" function to see the structure that gets returned.
6. In the "get_airtable" statement, change the name of the table from "Task" to "xTask" so that Airtable will return an error. Run the "test_task" function to examine the error message that gets returned.
7. Replaces the "get_tasks" function with this slightly more complex version that specifies a sort order for the records ad adds a general error trap.
function get_tasks(){// Gets the current list of stores from airtabletry{const sort=[{field: "sequence", direction: "asc"}]const data = get_airtable(base_id,api_key,"Task","",["sequence","group","task","details"],"",sort)if(data.error){return {status:"failure",message:data.error.message}}else{return {status:"success",records:data}}}catch(e){return {status:"failure",message:e.message}}}