Search Results for 'script'
-
Search Results
-
Topic: SQLite3 to Tap Forms
I put together a script to make the conversion from SQLite3 to Tap Forms easier. It is most useful for databases with multiple tables and many fields.
This BASH script is very rough – consider it BETA.
Information/download can be found here:
http://www.Cattail.Nu/tap_forms/tap_forms_sqlite3_port/index.htmlBrendan:
Documentation: addNewFieldNamedWithType needs other types
Documentation: createNewFormNamedUseful functionality I couldn’t find:
document.importCSV(fileURL, form, createFieldsIfMissing)
form.deleteFieldNamed(‘field’)
fld.required (and properties for other options)I found this javascript example & tried to adapt it but seems I did not get it right.
I am trying to calculate a monthly payment into the field that is this script (shown below).
The number of years of the loan, the principal balance of the loan & the annual percentage rate are already inputted manually in the same form. The script references those data points & does math to find the monthly payment.
Perhaps it could be done without javascript with a calculation field but the calculation is not simple, and this existing javascript example (meant for a web form) seemed like it should be workable if only it were formatted for tapforms. A few parts included in the original example (commented out) I am not trying to get to work at this time, just the part that concerns the loan payment amount.
function calculatePayment() {
// Source: https://www.oreilly.com/library/view/javascript-the-definitive/0596000480/ch01s08.html
// Get the user’s input from the form. Assume it is all valid.
// Convert interest from a percentage to a decimal, and convert from
// an annual rate to a monthly rate. Convert payment period in years
// to the number of monthly payments.// var principal = document.loandata.principal.value;
// var interest = document.loandata.interest.value / 100 / 12;
// var payments = document.loandata.years.value * 12;var principal = record.getFieldValue(‘fld-a37b001914c9476e85ff6e72dc5f7e41’);
var interest = record.getFieldValue(‘fld-ad2e6a56376f462fa750fee0eca40902’) / 100 / 12;
var payments = record.getFieldValue(‘fld-3aaee77c789642dbb64633cac5b9b210’) * 12;// Now compute the monthly payment figure, using esoteric math.
var x = Math.pow(1 + interest, payments);
var monthly = (principal*x*interest)/(x-1);// Check that the result is a finite number. If so, display the results.
if (!isNaN(monthly) &&
(monthly != Number.POSITIVE_INFINITY) &&
(monthly != Number.NEGATIVE_INFINITY)) {x = round(monthly);
// document.loandata.total.value = round(monthly * payments);
// document.loandata.totalinterest.value = round((monthly * payments) – principal);
}
// Otherwise, the user’s input was probably invalid, so don’t
// display anything.else {
x = “”;
// document.loandata.total.value = “”;
// document.loandata.totalinterest.value = “”;
}
}// This simple method rounds a number to two decimal places.
function round(x) {
return Math.round(x*100)/100;
record.setFieldValue(scr_TP_MortgagePayment,round(x));
form.saveAllChanges();
}calculatePayment();
Topic: Lifecycle hooks
I’m realizing that a lot of the things I am trying to do with scripts could be better accomplished with less complexity if there was a way to register a script to run on specific events. Specifically record creation and record change. This could two options next to “Ask before running” for “Run when records created” and “Run when records change” and the “record” binding would be said mutation.
I just finished assembling
Tap Forms Javascript Scripting 102http://www.cattail.nu/tap_forms/tap_forms_scripting_102/index.html
Do magical things with and to your data and forms.
This beginner level tutorial:
* Teaches you about the object model (document, forms, records, fields, values).
* Teaches you how to access and use the objects in scripts.
* Teaches you how to apply the documentation.
* Teaches you how to sort and filter record arrays to create reports.To follow this tutorial, you should be familiar with the topics covered in Tap Forms Javascript Scripting 101:
http://cattail.nu/tap_forms/tap_forms_scripting_101/index_review.htmlHappy coding !!!
Topic: Getting favicons
I’ve been using a form for storing bookmarks but text-only makes it hard to browse the list. Here’s a script that automatically fetches the favicon for each URL in a form. Obviously you would need to update with your own ids.
// https://stackoverflow.com/a/54947757/952123 const getHostname = (url) => { // run against regex const matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i); // extract hostname (will be null if no match is found) return matches && matches[1]; } function favIconURL(domain) { returnhttps://www.google.com/s2/favicons?domain=${domain}; } function getFavIconURL(url) { return favIconURL(getHostname(url)); } function getFavicon(r) { const url = r.getFieldValue('fld-026ad10a88d74569a6d37b19aa7b77a6'); console.log(getFavIconURL(url)); r.addPhotoFromUrlToField(getFavIconURL(url), 'fld-42eeb21b65464cb39aa966772620acba', { "filename": "favicon", "prevent_duplicates": true}) } function getIfEmpty(r) { const thumbnail = r.getFieldValue('fld-42eeb21b65464cb39aa966772620acba'); if (thumbnail.length) return; return getFavicon(r); } form.getRecords().forEach(getIfEmpty); form.saveAllChanges();