Exporting to a CSV file with Javascript

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Exporting to a CSV file with Javascript

Viewing 5 reply threads
  • Author
  • December 23, 2021 at 9:20 AM #46164

    Victor Warner

    I would like to create a CSV file through a form script, as it will be much quicker/more automated than going through the File/Export/Export option.

    I have been able to create a script which uses Utils.copyTextToClipboard() to get the data out (and then using the clipboard to insert it into an AppleScript). It appears to work, but was wondering whether it is also possible to write the data to a file rather than the clipboard?

    The script as far as I have got with it:

    var client_name = record.getFieldValue('fld-ffa7651ff5bd48a9aa8184a69be8550e');
    var email = record.getFieldValue('fld-152d99920304499f8f89c3868eb144d1');
    var details = record.getFieldValue('fld-23c8168c1deb45bfbcabc862ad6e5199');
    var date_prescribed_information_provided = record.getFieldValue('fld-0bf58a5d40b3430f8745b86b2a49775a');
    var document_details = record.getFieldValue('fld-b8a4b0731dc94f46abf28eab828abc4e');
    var number_of_documents = record.getFieldValue('fld-7ba7df82977945988aac2598dc528a75');
    var amount_of_notary_charge = record.getFieldValue('fld-648fee2d0eaa4e7d973fe86bde1d504f');
    var what_will_third_parties_be_providing = record.getFieldValue('fld-abfb6ffd2c7c4695972ed54ec463fc08');
    var third_party_charge_plus_charge_to_arrange = record.getFieldValue('fld-8cc4031614d7402aa5e131d33ae1c039');
    var final_charge = record.getFieldValue('fld-6b86691517dc4b8b8efa63b7da98185d');
    var second_individual_client_name = record.getFieldValue('fld-772ee93b5eb747d294e5a9a7b548ebda');
    var second_individual_email = record.getFieldValue('fld-d09998df75864a0e8f82b6f61188b537');
    // set email for prescribed information document
    if (second_individual_client_name){
    var email_for_prescribed_information = email + " and " + second_individual_email;
    } else {
    var email_for_prescribed_information = email;
    var date_formatted = date_prescribed_information_provided.toLocaleDateString("en-GB", { year: 'numeric', month: 'long', day: 'numeric' });
    var lines = client_name + ";" + email_for_prescribed_information + ";" + details  + ";" + date_formatted + ";" + document_details + ";" + number_of_documents + ";" + amount_of_notary_charge + ";" + what_will_third_parties_be_providing + ";" + third_party_charge_plus_charge_to_arrange + ";" + final_charge + ";" + second_individual_client_name + ";" + second_individual_email;
    //	Utils.copyTextToClipboard(JSON.stringify(record.first_name_id));
    December 24, 2021 at 12:20 AM #46166

    Sam Moffatt

    I don’t think there is a way within TF to write to disk directly but the way I’ve solved it is via a web service that writes files on my behalf. The other way is to sync to CouchDB and pull the data directly from CouchDB as well. It’s not a trivial example though and to do it securely is harder again.

    December 24, 2021 at 3:11 AM #46168

    Victor Warner


    Thank you for letting me know.

    December 24, 2021 at 3:42 AM #46170


    I haven’t written any write to disk API for the scripting engine, but I should definitely do that.

    December 24, 2021 at 3:43 AM #46171


    Although there are post commands that you can send to a URL. If you had a web service that could accept it:

    Utils.postContentToUrlWithContentType(some_string, url, 'application/json');

    December 24, 2021 at 5:22 PM #46175

    Sam Moffatt

    The other thing that makes this increasingly difficult is that out of the box MacOS is removing support for the scripting languages that it used to ship by default so getting back PHP on the Mac is increasingly hard.

Viewing 5 reply threads

You must be logged in to reply to this topic.