The Tap Forms JavaScript Application Programming Interface (API) provides you with specific extensions to the JavaScript virtual machine that lets you create, update, and delete various objects within your Tap Forms database document.

Here are a list of objects and the functions you can call on each.

document

Function Parameters Returns Description Example
saveAllChanges none Bool Call this to save any changes your script has made to the database document. document.saveAllChanges();
getForms none array of forms Call this to fetch an array of all the forms in your database document. document.getForms();
getFormNamed form name form Call this to fetch a form with the specified name. document.getFormNamed('My Movie Library');

form

Function Parameters Returns Description Example
addNewRecord none record Adds a new record to the form. var newRecord = form.addNewRecord();
getRecords none array Returns an array of record objects for the specified form. var records = form.getRecords();
deleteRecord record error string Deletes the specified record from the form. form.deleteRecord(someRecord);
saveAllChanges none Bool Call this to save any changes your script has made to the database document. document.saveAllChanges();
getFieldIds none array Returns an array of all the field IDs in the form. form.getFieldIds();
getFields none array Returns an array of all the TFField objects in the form. form.getFields();
getFieldsForType type (text, number, check_mark, date, time, date_time, calc, note, etc.) array Returns an array of all the TFField objects in the form for the specified type. form.getFieldsForType('text');
getFieldNamed text Field Returns the TFField object for the specified field name. form.getFieldNamed('Movie Title');
getFieldWithId field ID Field Returns the TFField object for the specified field ID. form.getFieldWithId('fld-abcde1234');
getID none form ID Returns the internal unique ID of the form. form.getID();
getAvgOfField field ID number Returns the average value of all the records in the form for the specified field. form.getAvgOfField(fieldID);
getMinOfField field ID number Returns the minimum value of all the records in the form for the specified field. form.getMinOfField(fieldID);
getMaxOfField field ID number Returns the maximum value of all the records in the form for the specified field. form.getMaxOfField(fieldID);
getTotalOfField field ID number Returns the total sum of all the records in the form for the specified field. form.getTotalOfField(fieldID);
getSearchNamed text Search Returns a search object given the name of a search. form.getSearchNamed('Genre: Action & Adventure');
runScriptNamed text none Runs the Form Script with the specified name. Used for including scripts inside other scripts. form.runScriptNamed('Common Functions');
selectRecord record none Selects the specified record on the form. form.selectRecord(someRecord);

field

Function Parameters Returns Description Example
name none text Returns the name of the field. field.name;
fieldType none text Returns the type of the field. field.fieldType;
fieldDescription none text Returns the description of the field. field.fieldDescription;
getID none field ID Returns the internal unique ID of the field. field.getID();

search

Function Parameters Returns Description Example
getRecords none array Returns an array of record objects for the specified search. var records = search.getRecords();
getTotalOfField field ID number Returns the total sum of all the records in the search for the specified field. search.getTotalOfField(fieldID);
getMinOfField field ID number Returns the minimum value of all the records in the search for the specified field. search.getMinOfField(fieldID);
getMaxOfField field ID number Returns the maximum value of all the records in the search for the specified field. search.getMaxOfField(fieldID);
getAvgOfField field ID number Returns the average value of all the records in the search for the specified field. search.getAvgOfField(fieldID);

record

Function Parameters Returns Description Example
addNewRecordToField field_id record Used for adding a new record to a Link to Form or Table field. var newRecord = record.addNewRecordToField(field_id);
addRecordToField record, field_id none Used for adding an existing record to a Link to Form or Table field. record.addRecordToField(someRecord, field_id);
addPhotoFromUrlToField url, field_id none Fetches a photo from the specified URL and adds it to the Photo field specified by field_id record.addPhotoFromUrlToField(image_url, case_cover_id)
getFieldValue field_id object Gets the value for the specified field from the record. The return type depends on the field you’re getting the value from. var barcode = record.getFieldValue(barcode_id);
setFieldValue field_id, value none Sets the value on the specified field. record.setFieldValue(movie_title_id, 'The Terminator');
setFieldValues dictionary none Sets the values on multiple fields at once given a dictionary of field ids and values. record.setFieldValues({ [field1_id]: "value1", [field2_id]: "value2", [field3_id]: "value3" });
getID none record ID Returns the internal unique ID of the record. record.getID();
getNoteFieldValue field_id note value Gets the rich text note field value from the specified Note field. record.getNoteFieldValue(field_id');
getUrl none url Gets the URL for the record. This is the same URL as the Copy Record Link function under the Edit menu. record.getUrl();
removeRecordFromField record, field_id none Removes a record from a Link to Form or Table field. record.removeRecordFromField(childRecord, field_id');
recordExistsInField record, field_id boolean Returns true if the record exists in the Link to Form or Table field. record.recordExistsInField(field_id');
setNoteFieldValue field_id, value none Sets the rich text note field value on the specified Note field. record.setNoteFieldValue(field_id, note_value');

Utils

Function Parameters Returns Description Example
getJsonFromUrl url JSON For the specified URL, returns a JSON response that you can get values from. var product_info = Utils.getJsonFromUrl(url);
getTextFromUrl url text For the specified URL, returns a text response. var product_info = Utils.getTextFromUrl(url);
getDataFromUrl url binary data For the specified URL, returns a binary data response. var photo_data = Utils.getDataFromUrl(url);
postJsonToUrl JSON, url dictionary For the specified URL, posts the JSON content. Utils.postJsonToUrl(json_string, url);
postContentToUrlWithContentType text, url, content type dictionary For the specified URL, posts the text content using the specified content type. Utils.postContentToUrlWithContentType(some_string, url, 'application/json');
alertWithMessage title, message none Displays an alert with the specified title and message Utils.alertWithMessage('Script Run Complete!', 'Cool!!!!!');

Prompter() function – for prompting for input.

You can also prompt a user for input parameters, then take the input and use it for populating fields. This currently only works on the Mac version. Here’s an example:

var output = function printOut(continued) {
       if (continued == true) {
	   console.log(username + ", " + password + ", " + email_address + ", " + other_field + ", " + genre);
       } else {
          console.log("Cancel button pressed.");
       }
}


var username;
var password;
var email_address;
var other_field;
var genre;
var genres = ['Action & Adventure', 'Comedy', 'Drama', 'Horror', 'Science Fiction'];

let prompter = Prompter.new();
prompter.cancelButtonTitle = 'No Thanks';
prompter.continueButtonTitle = 'Go For It!';
prompter.addParameter('Username: ', 'username')
.addParameter('Password: ', 'password', 'secure')
.addParameter('Email Address: ', 'email_address')
.addParameter('Other: ', 'other_field')
.addParameter('Genre: ', 'genre', 'popup', genres)
.addParameter('Media Type: ', 'media_type', 'picklist', 'Media Types List')
.show('Enter a Username and Password and Stuff', output);

Need more help with this?
Don’t hesitate to contact us here.

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.