Tap Forms app icon half
Tap Forms Forum text image
Blue gradient background

Exchange tips and ideas with the Tap Forms community

Search Results for 'script'

Viewing 15 results - 1,711 through 1,725 (of 2,989 total)
  • Author
    Search Results
  • #41943

    In reply to: SQLite3 to Tap Forms

    Sam Moffatt
    Participant

    There is a command called pbcopy that will accept input from the CLI and dump something on the clipboard. I use it to reformat text from eBay listings into NVP and dump on my clipboard to paste into Tap Forms table fields. Could skip a round trip to TextEdit in the middle there for you.

    A cool feature would be a Javascript helper to import CSV files from disk to skip the import wizard.

    I also haven’t seen Hungarian notation in so many years! Blast from the past.

    #41941
    T.L. Ford
    Participant

    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.html

    Brendan:
    Documentation: addNewFieldNamedWithType needs other types
    Documentation: createNewFormNamed

    Useful functionality I couldn’t find:
    document.importCSV(fileURL, form, createFieldsIfMissing)
    form.deleteFieldNamed(‘field’)
    fld.required (and properties for other options)

    #41940
    Philip Gibson
    Participant

    Thanks, Daniel and Brendan. I’ve just taken a look. I think I’m going to need to learn how to write a script in FileMaker. I hoped I could copy and paste and tweak the code. Unfortunately it doesn’t work like that. Right now, I don’t have time to investigate further but I’ll put it on my to-do list. Thanks again and best wishes.

    #41939
    Brendan
    Keymaster

    Ah yes. Some sort of FM Script:

    Go to Record/Request/Page [ First ]
    Loop
    	Set Variable [ $PATH ; Value: Get ( DocumentsPath ) & GetContainerAttribute ( Products::Container ; "filename" ) ]
    	Export Field Contents [ Products::Container ; "$PATH" ; Create folders: Off ]
    	Go to Record/Request/Page [ Next ; Exit after last: On ]
    End Loop
    #41901
    Michael Tucker
    Participant

    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();

    #41897

    In reply to: Lifecycle hooks

    cf
    Participant

    Even though there already exist triggers for specific fields I think there’s still value in having a trigger for any record mutation, separate from field scripts. I have a few forms where fields depend on each other and need to be refreshed in the right order, if a trigger simply fired on any change I could just go through all fields and update them. Of course record. creation/deletion would be the most valuable of them all since there’s really nothing like it right now.

    #41895

    In reply to: Colors for date field

    Sam Moffatt
    Participant

    Couldn’t you use a script field to refer to the date field and copy it to a hidden text field that is associated to the pick list? You’d probably still have to manually create the pick list though and assign the colours so it doesn’t save the colour assignment side.

    Though perhaps as a feature for future could you have a sliding colour palette? A sorted autolist with an autopalette would work here and so long as you had a range to work with on the HSV scale it wouldn’t be too hard to implement or a set of predefined colour palettes. Random thoughts.

    Another feature could be programatic manipulation of pick lists as well to set colour values. Or even just set it directly on the record like the record colour.

    #41888

    In reply to: Lifecycle hooks

    Sam Moffatt
    Participant

    Yes, this is another one on my backlog; ideally a pre and post hook too as well as more metadata about what/why something is triggered for debugging purposes. I’ve got a quirk right now where scripts are firing more than I expect them to be and it’s confusing.

    #41886

    In reply to: Lifecycle hooks

    Brendan
    Keymaster

    Ya, that’s a good idea. I believe Sam asked for something like that a while ago. He wanted to be able to have triggers in Tap Forms for running scripts. Right now the triggers are if a field value is modified, a script runs.

    #41885

    Topic: Lifecycle hooks

    in forum Script Talk
    cf
    Participant

    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.

    #41884
    T.L. Ford
    Participant

    Cristian, I agree with you entirely. I was merely pointing it out because my first run with Core Data had me grinding my teeth trying to adapt to a lack of IDs.

    I don’t have the iOS version, but I know there are some differences from reading the forums.

    Point #4 can be worked around with a script field that builds what you want displayed. A bit rough, but tolerable.

    – T

    #41878
    T.L. Ford
    Participant

    As a field level script, it looks like this:

    function Characters() {
    
    	var select_characters = record.getFieldValue('fld-70910404166b458b8147aaf560efb4eb');
    	var characters = select_characters.split(",");
    
    	// put into an array so we can easily sort it
    	var characters_array = {};
    	
    	// jumping by 4, because that's the number of fields
    	for (var index = 0, count = characters.length; index < count; index += 4){
    		var arr = { 
    			characters[index], 
    			characters[index + 1], 
    			characters[index + 2], 
    			characters[index + 3] 
    		};
    		characters_array.push(arr);
    	}
    	characters_array.sort(function(a,b) {
    		if (a[0] > b[0]) { return 1; }
    		if (a[0] < b[0]) { return -1; }
    		return 0;
    	});
    
    	var badge = "Field Badge #: ";
    	var fname = "Field Name: ";
    	var trade = "Field Trade: ";
    	var company = "Field Company: ";
    
    	for (index = 0, count = characters_array.length; index < count; index++){
    		badge += characters_array[index][0] + ", ";		fname += characters_array[index][1] + ", ";		trade += characters_array[index][2] + ", ";		company += characters_array[index][3] + ", ";
    	}
    	badge = badge.splice(0,-2);
    	fname = fname.splice(0,-2);
    	trade = trade.splice(0,-2);
    	company = company.splice(0,-2);
    
    	return badge + "\n" + fname + "\n" + trade + "\n" + company;
    }
    
    Characters();

    See the attached.

    #41872
    Mark Rudolphi
    Participant

    Sorry – just realized that required fields in forms does not prevent adding empty entries. That would be nice if it would prevent an entry from being added if it didnt have anything in it. I suspect that can be done via a script but I dont know for sure.

    #41869
    T.L. Ford
    Participant

    I just finished assembling
    Tap Forms Javascript Scripting 102

    http://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.html

    Happy coding !!!

    #41846

    Topic: Getting favicons

    in forum Script Talk
    cf
    Participant

    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) {
    	return https://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();
    
Viewing 15 results - 1,711 through 1,725 (of 2,989 total)