new Service_Airtable()
Assumes your workspace only consists of two columns of records that are "Name" and "Value", each of a single line text type
Example
var AirtableElement = document.getElementById("service_airtable");
AirtableElement.setAttribute("apikey", "APIKEY");
AirtableElement.setAttribute("baseid", "BASEID");
AirtableElement.setAttribute("tablename", "TABLENAME");
AirtableElement.init();
Methods
-
async, inner init(APIKey, BaseID, TableName, pollIntervalInput) → {boolean}
-
initialize Service_Template Starts polling the external API this function needs to be executed after executeAfterInit but before all other public functions
Parameters:
Name Type Description APIKey
string API Key
BaseID
string Base ID for Table in which data is stored
TableName
string Table Name of Base
pollIntervalInput
integer interval at which to get entries from the cloud in MILISECONDS. Default value is 1000 ms.
Returns:
boolean -True if service was successsfully initialized, false otherwise
Example
var AirtableElement = document.getElementById("service_airtable"); var myAirtable = AirtableElement.getService(); myAirtable.init("APIKEY", "BASEID", "TABLENAME")
-
inner executeAfterInit(callback)
-
Get the callback function to execute after service is initialized This function needs to be executed before calling init()
Parameters:
Name Type Description callback
function function to execute after initialization
Example
myAirtable.executeAfterInit( function () { // your API code })
-
inner isActive() → {boolean}
-
Get whether the Service was initialized or not
Returns:
boolean -whether Service was initialized or not
Example
if (myAirtable.isActive() == true) // do something if Airtable service is active
-
inner getEntriesInfo() → {object}
-
Get all entries on the cloud.
Returns:
object -all entries on the cloud, an object with Name fields as keys and Value fields as values
Example
let entriesInfo = myAirtable.getEntriesInfo(); console.log(entriesInfo); // display all entries information // display message entry info let messageEntryType = entriesInfo["message"].type; let messageEntryValue = entriesInfo["message"].value; console.log("message has value of ", messageEntryValue, "that is of type ", messageEntryType);
-
async, inner setEntryValueNotStrict(name, value, callback)
-
Update Value of a entry on Airtable by entry Name. If the entry does not exist, create a new entry and assign given properties.
NotStrict property indicates that the data type of the Value supplied will be implicitly converted. For example, allowing for setting an INT entry's value with a string, "123" or a STRING entry's value with * a number. This method exists for convenience but please avoid using it extensively as it can lead to unpredictable outcomes.Parameters:
Name Type Description name
any Name of entry
value
any new Value to update entry to.
callback
any function to run after new entry value or new entry creation
Example
// set a string type Value of a Entry and display myAirtable.setEntryValueNotStrict("message", 123, function () { let messageValue = myAirtable.getEntryValue("message"); console.log("message: ", messageValue); // display the updated value, which will be 123. }) // set value of a boolean Entry myAirtable.setEntryValueNotStrict("aBoolean", true); // set value of an integer Entry myAirtable.setEntryValueNotStrict("anInteger", 10); myAirtable.setEntryValueNotStrict("anInteger", "10"); // set value of a double Entry myAirtable.setEntryValueNotStrict("aDouble", 5.2); myAirtable.setEntryValueNotStrict("aDouble", "5.2");
-
async, inner setEntryValueStrict(name, value, callback)
-
Update Value of a entry on Airtable by entry Name. If the entry does not exist, create a new entry and assign given properties.
The value of the Entry is not implicitly converted. E.g. setting a string Entry's value with a number will no longer workParameters:
Name Type Description name
string Name of entry
value
any new Value to update entry to
callback
any function to run after new entry value or new entry creation
Example
// set a string type Value of a Entry and display myAirtable.setEntryValueNotStrict("message", 123, function () { let messageValue = myAirtable.getEntryValue("message"); console.log("message: ", messageValue); // display the updated value, which will be 123. }) // set value of a boolean Entry myAirtable.setEntryValueNotStrict("aBoolean", true); // set value of an integer Entry myAirtable.setEntryValueNotStrict("anInteger", 10); // set value of a double Entry myAirtable.setEntryValueNotStrict("aDouble", 5.2);
-
inner getEntryValue(name) → {any}
-
Get the Value field associated with a entry by its Name
Parameters:
Name Type Description name
string Name of entry
Returns:
any -the Value field in any JS data type. data type conversion is implicit.
Example
let value = myAirtable.getEntryValue("message"); console.log("message: ", value);
-
async, inner deleteEntry(name, callback)
-
Delete entry from the Airtable database given its Name field.
Parameters:
Name Type Description name
any the Name of entry to delete
callback
any callback function to run after entry deletion
Example
myAirtable.deleteEntry("message", function () { let entriesInfo = myAirtable.getEntriesInfo(); console.log("entriesInfo: ", entriesInfo); // entriesInfo will no longer contain the entry that was deleted })
-
async, inner createEntry(name, value, callback)
-
Create a new entry given its Name field and Value field. If a entry with given name already exists, the method will throw an Error.
Parameters:
Name Type Description name
string name of entry to create
value
any value to give entry (can be of any JS data type)
callback
function function to run after entry creation
Example
myAirtable.createEntry("aBoolean", false, function () { let aBoolean = myAirtable.getEntryValue("aBoolean"); if (aBoolean == false) console.log ("aBoolean is false"); })