createRecordSync

Category:Data

Adding permanent data storage to your apps is the last step to making them real-world. The apps you use everyday are driven by data "in the cloud".

First time using App Lab table data storage? Read a short overview of what it is and how to use it here.

The record parameter must be a javascript object variable or a javascript object defined using curly brace and colon notation (see examples below). The object cannot have an "id" property. The record created in the table is then returned as a parameter to the callback function. Data is only accessible to the app that created the table. To View your app's table data, click 'View data' in App Lab and click the table name you want to view.

Examples

Simple Survey

Collect favorite food data from friends and store it in a table.

// Collect favorite food data from friends and store it in a table.
textInput("nameInput", "What is your name?");
textInput("ageInput", "What is your age?");
textInput("foodInput", "What is your favorite food?");
button("doneButton", "Done");

onEvent("doneButton", "click", function() {
  var favFoodData={};
  favFoodData.name = getText("nameInput");
  favFoodData.age = getNumber("ageInput");
  favFoodData.food = getText("foodInput");
  createRecordSync("fav_foods", favFoodData);
});

Syntax

createRecordSync(table, record)

Parameters

NameTypeRequired?Description
table String The name of the table the record should be added to. A new table gets created if it doesn't exist.
record Object The data to be stored in the record. Either a javascript object variable or a javascript object defined using curly brace and colon notation (see examples above).

Tips

Tips

  • The javascript object properties must match the App Lab table column names. Both are case sensitive.
  • Duplicate records are allowed in a table but will have different id values assigned automatically.
  • Use with readRecords(), deleteRecord(), and updateRecord() records to view, delete, and update records in a table.

Found a bug in the documentation? Let us know at documentation@code.org