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 - 901 through 915 (of 2,989 total)
  • Author
    Search Results
  • #47222
    Brendan
    Keymaster

    Hi Michael,

    I added back-ticks around your code so it’s easier to read.

    That looks like it should work. But record is a keyword that means to use the currently selected record. In the script I would change record to rec or something like that. See if that solves the problem.

    Thanks,

    Brendan

    #47217
    Brent Willingham
    Participant

    I think this thread pretty well describes what I am looking to do. I want to create a database that tracks activities and expenses related to Wildlife Management Practices that need to be done to maintain a wildlife exemption on a property. There are 7 different pre-defined main management practices and each has it’s own set of sub-practices. So a parent/child pick list situation – I think. There would be a Management Practice field that has a pull down pick list. Depending on which practice is chosen, it’s respective sub practice list would appear in the Sub Practice field.

    Since I’m a novice and don’t have any experience with scripting, I think I’d be ok with Sam’s idea in Reply 43418: “If you have a few options, you could use the built in pick lists and create one for each of the levels.”

    I don’t expect the categories or sub-categories to change so I don’t mind creating pick lists for each of the levels – I just don’t really know how to get started here.

    Thanks,
    Brent

    #47216
    Victor Warner
    Participant

    I am using the prompter function and for a popup list is it possible for one to be the default?

    On running the script, the default is “Unspecified”

    For example in the following code for passport_type_list variable, I would like the first entry (‘United Kingdom of Great Britain and Northern Ireland passport’) to be automatically shown rather than ‘Unspecified’.

    var heshe;
    var heshe_list = ['his', 'her'];
    var director_signee;
    var passport_type;
    var passport_type_list = ['United Kingdom of Great Britain and Northern Ireland passport', 'Irish passport', 'United States of America passport'];
    
    let prompter = Prompter.new();
    prompter.cancelButtonTitle = 'Cancel';
    prompter.continueButtonTitle = 'Continue';
    prompter.addParameter('Passport type: ', 'passport_type', 'popup', passport_type_list)
    prompter.addParameter('He or she: ', 'heshe', 'popup', heshe_list)
    prompter.addParameter('Name of the director signing: ', 'director_signee')
    .show('Choose whether there is a he or she\n\n\nIf a company then put in name of director signing',output);
    • This topic was modified 3 years, 8 months ago by Brendan.
    #47212
    Daniel Leu
    Participant

    Yes, using a custom layout you can place buttons that execute a script. It is a big time saver.

    In the custom layout editor, select the ‘add run script button…’ at the top right, place the button on your layout, and the set the button script.

    Attachments:
    You must be logged in to view attached files.

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #47211
    Tom Vogt
    Participant

    Is there a way to create a button (or something looking like a button) in a layout and trigger a script through it?

    I’m building a simple book keeping thing with Tap Forms for my wife and she’s a complete non-techie. Starting a script from the menu would work for me, but for her a button right at the right place in a layout would be much better.

    #47204
    Michael Tucker
    Participant

    I have fields just two fields that need to operate in a form….

    ShareSell$Amt (numeric, id:fld-89c6961ad2ec43e8853ff13e052fc807)
    NextRung$Amt (calculation, id:fld-276de1515a7c4054b9df9410cbbefd29)

    I just want after a find of the fields involved, to run a script to
    read in the first found record field NextRung$Amt,
    move to the next record and insert that read amount into field ShareSell$Amt,
    then continue thru the found set of records.

    The first record has the beginning ShareSell$Amt that is calculated in the record as NextRung$Amt.

    The function I’m looking for — is that number from the field NextRung$Amt is picked up and put into the next record’s ShareSell$Amt, and that makes that record calculate a new NextRung$Amt, which is picked up and put into the next record, then on until records in the found set run out.

    This script just stops on the first record, so it needs something.

    function Calc_NextRung_LADDER4() {
    	let balance = 000000;
    	var nextrung_id = 'fld-276de1515a7c4054b9df9410cbbefd29';
    	var newsharesell_id = 'fld-89c6961ad2ec43e8853ff13e052fc807';
    	//var transaction_date_id = 'fld-2567fc59b0ce45f982f2fe2d20eb0d79';
    	//need a saved find 'Calc_Balances LADDER4'
    	//Sam Moffatt, Tap Forms Forum, 10/21/2019 #37289
    	
    	for(record of form.getSearchNamed('Calc_Balances LADDER4').getRecords())
    	{
    		balance += record.getFieldValue(nextrung_id);
    		record.setFieldValue(newsharesell_id, balance);
    	}
    	document.saveAllChanges();
    }
    
    Calc_NextRung_LADDER4();

    In the screenshot, this set has 8 records or “rungs”. Theoretically the script would populate the 7 following rungs or records after the amount is first set to begin in the first record.

    Thanks for those that make these things easy for those of us who infrequently dabble in scripts,
    Mike

    • This topic was modified 3 years, 8 months ago by Brendan.
    Attachments:
    You must be logged in to view attached files.
    #47201
    Stig Widell
    Participant

    Hi,
    The Swedish farmer now has an excellent tool with Tap Forms 5 in organizing cows and calves. Two script are involved created by Brendan and Sam, thanks to both of them.
    However there is a need for one more script.
    The birth date of a calf in form “Kalvningar” is equal to the delivery date for the mother cow. In the form “Rekryteringsdjur” there is a list of all deliveries for a cow.
    Now there is a need for a field in “Rekryteringsdjur” identifying the date of the cows latest delivery.
    I hope someone can help me!!
    Enclose the template.

    Attachments:
    You must be logged in to view attached files.
    #47197
    Brendan
    Keymaster

    Hi Ed,

    So are you looking for some sort of a dashboard or something?

    You could do that with a Form Script that fetches totals from fields from different forms and then displays them in a form.

    See the scripting topic here:

    https://www.tapforms.com/help-mac/5.3/en/topic/scripts

    To get a total of a field from a specific form, you can use code like this:

    function populateFormTotals() {
    
       // get the form you want a total from
       var form1 = document.getFormNamed("Form 1");
    
       // get the field ID you want the total from
       var form1Field1Id = form1.getFieldNamed("Quantity").getId();
    
       // get the total for all records in form1 for the specified field.
       var totalOfForm1Field1 = form1.getTotalOfField(form1Field1);
       
       // put the total into a field on this form.
       var totalField1Id = form.getFieldNamed("Total Field 1").getId();
       record.setFieldValue(totalOfForm1Field1, totalField1Id);
       form.saveAllChanges();
    }
    
    populateFormTotals();

    You would then want to populate all the fields in your form with the values obtained from the different forms and fields. But you have to decide what those would be.

    Then whenever you want to see the overall totals, just run the form script again and the fields will update.

    Thanks,

    Brendan

    • This reply was modified 3 years, 8 months ago by Brendan.
    johnny_law
    Participant

    I just started having the same problem with a script I use everyday that programmically adds rows to a child form using the command “ record.addNewRecordToField(id)”

    The first time a row is added it is linked to the parent form. The subsequent rows are not.

    This broke with the last update I just updated yesterday to version 5.3.24.

    Prior to this version it was working great.

    Regards,

    Johnny

    • This reply was modified 3 years, 9 months ago by johnny_law.
    Victor Warner
    Participant

    In a post I received a help from Sam Moffat and Brendan on how to create, from one form, a set of records in a linked form with a form script. (The post: https://www.tapforms.com/forums/topic/how-to-add-more-than-one-record-at-a-time-using-a-form-script/).

    The script below work correctly (it creates the records in the link). However, only the first record created in the linked form is linked. The others are not linked, and it is necessary to go through them one by one to create the link.

    The field linking the two forms is Link to Form, One to Many.

    Is there a way to overcome this? Any help would be gratefully received.

    The script:

    `// Fields from Time Spent form
    var order_of_records_id = ‘fld-d78467379e004205b7893109bca23db2’;
    var date_of_activity_id = ‘fld-5b07fd9bb7b441848d31de782bcd8780’;
    var time_spent_id = ‘fld-be5bcddb8b46426eb90dded15790ef89’;
    var activity_id = ‘fld-160340262dbd416291dbeebd7119bd86’;
    var description_of_activity_id = ‘fld-c4316e0ee4e7457b92b2f8cc6f699200’;

    // Date fields

    // Add today’s date
    var date_signed = new Date();

    // Formatted to 23/04/2022 for entry in a time entry
    var date_signed_formatted = date_signed.toLocaleDateString(“en-GB”, { year: ‘numeric’, month: ‘long’, day: ‘numeric’ })

    console.log (date_signed + “\n” + date_signed_formatted);
    var output = function printOut(continued) {
    if (continued == true) {

    console.log(heshe + ‘\n\n\n’ + date_signed + date_signed_formatted);

    let entries = [{
    [order_of_records_id]: “1”,
    [date_of_activity_id]: new Date(),
    [time_spent_id]: “6”,
    [activity_id]: “Calls & emails”,
    [description_of_activity_id]: “”
    },
    {
    [order_of_records_id]: “2”,
    [date_of_activity_id]: new Date(),
    [time_spent_id]: “6”,
    [activity_id]: “See and identify client”,
    [description_of_activity_id]: “See client at [ ] – identify client by ” + heshe + “United Kingdom of Great Britain and Northern Ireland passport and a second form of identification”
    },
    {
    [order_of_records_id]: “3”,
    [date_of_activity_id]: new Date(),
    [time_spent_id]: “12”,
    [activity_id]: “Discuss client’s document(s)/matter, see client sign document(s)”,
    [description_of_activity_id]: “Client [ ]\n\nObtain confirmation that:\n\n(i) client has read the Power of attorney, \n\n(ii) the facts and information contained in the Power of attorney are correct,(iii) client is willing to be bound by the Power of attorney; and \n\n(iv) client is willing to grant the power of attorney in favour of the person(s) named in the power of attorney\n\nOn ” + date_signed_formatted + ” at [ ] and [name of client] signed the power of attorney in favour of person named as the attorney in my presence as a deed with myself acting as a witness”
    },
    {
    [order_of_records_id]: “4”,
    [date_of_activity_id]: new Date(),
    [time_spent_id]: “12”,
    [activity_id]: “Notarise document”,
    [description_of_activity_id]: “Prepare covering certificate for 1 document (Power of attorney) and attach the covering certificate to the Power of attorney document – bind, seal and sign”
    },
    {
    [order_of_records_id]: “5”,
    [date_of_activity_id]: new Date(),
    [time_spent_id]: “6”,
    [activity_id]: “Arrange for legalisation/apostille”,
    [description_of_activity_id]: “Arrange with legalisation agent to collect 1 document (Power of attorney) and then obtain apostille using normal service of the Foreign, Commonwealth and Development Office, and deliver the documents by courier”
    },
    {
    [order_of_records_id]: “6”,
    [date_of_activity_id]: new Date(),
    [time_spent_id]: “”,
    [activity_id]: “Write up notarial register”,
    [description_of_activity_id]: “”
    }

    ];

    for (let entry of entries) {

    let newRecord = record.addNewRecordToField(‘fld-d6d2f3fd370a45c2b0d2b281fe012784’);

    newRecord.setFieldValues(entry);

    }

    document.saveAllChanges();

    } else {
    console.log (“Cancel button pressed.”);

    }

    }

    var heshe;
    var heshe_list = [‘his’, ‘her’];

    let prompter = Prompter.new();
    prompter.cancelButtonTitle = ‘Cancel’;
    prompter.continueButtonTitle = ‘Continue’;
    prompter.addParameter(‘He or she: ‘, ‘heshe’, ‘popup’, heshe_list)
    .show(‘Choose whether there is a he or she’,output);`

    #47152
    Tom Vogt
    Participant

    Hm.

    Is there a way to script this, basically “when opening this view, refresh records” ?

    #47141
    Tom Vogt
    Participant

    I’m currently testing the trial version. One thing I did was a report that collects data from various forms via a “link to other form” field. So I have three tables of data in there. Then I have a calculation field that basically sums these all up. Basically, fixed expenses, variable expenses, sales and then monthly result = TOTAL(sales) – (TOTAL(fixed_expenses) + TOTAL(variable_expenses))

    The problem I face is that this final sum isn’t updated when I update records in the related tables. I can manually update it by double-clicking to open it and then just press save. But it doesn’t update by itself. I have checked that it is NOT set to “calculate only once”.

    Is this a bug or a feature where I forgot to set some toggle somewhere, or is there something I can do about it with a script?

    #47135
    Brendan
    Keymaster

    Hi Anthony,

    Check to make sure that the Link to Form field has the form selected on it still. Are you using a Script field to pull in the data from the Link to Form field into the parent form? If you’d like to email me your form template from the device it’s not working on, I can take a look at it for you.

    Thanks,

    Brendan

    #47098
    Anonymous
    Inactive

    Thank you Brendan. In case anybody is interested to alter the column of a table field (‘intensity’ in the example) in a form according to some other field in the form:

    Solution according to Daniel Leu:

    Define a (hidden) script field in the form:

    
    function Intensity_Calculation() {
    	var onerm = record.getFieldValue('fld-22846df6ecc24d0d8c4cf9dfbb7ea75a');
    	var table = record.getFieldValue('fld-f59e078819e24d2aa1492d36d8fe268c');
    	
    	for (var index = 0, count = table.length; index < count; index++){
    		var intensity = table[index].getFieldValue(
                   'fld-d12f0981ef2c426988233a09cf0d9bb0')/onerm;
    
    		table[index].setFieldValue('fld-fb5ff2183ad24d62a4a11ced1922b6ea', intensity);
    	}
    }
    
    Intensity_Calculation();
    

    Solution according to Brendan via a script inside the table field:

    
    function Intensity_2() {
    
    	// Getting the field value from the field 'Weight' in the table, 
            // is used in the following calculation and triggers
    	// the script to execute when the field 'Weight' is modified.
    	
            var weight = record.getFieldValue('fld-d12f0981ef2c426988233a09cf0d9bb0');
    	
    	// The id of the field 'OneRm' of the parent form.
    	var parent_one_rm_id = 'fld-22846df6ecc24d0d8c4cf9dfbb7ea75a';
    	
    	// Getting the value of field 'OneRm'	
    	var parent_one_rm_id = record.parentRecord.getFieldValue(parent_one_rm_id);
    		console.log(parent_one_rm_id);
           
           	// A simple calculation		
    	var intensity_2 = weight/parent_one_rm_id;	
    
    	return intensity_2;
    
    }
    
    Intensity_2();
    

    See also the attached form template.

    Cheers.

    #47094
    Chris Ju
    Participant

    I saw when looking through the upper part of the script again that I had already “converted” the date (some months ago with your help… Thanks again for that!). I now changed that part, that “20” is added to the “short year”. However, this leads to errors with dates with years before 2000…

    But why does the problem appear in the new version?

    BTW: Does anyone know, why the “header: true” option doesn’t work?


    // function Importiere_Receipts_Daten() {

    // this imports the Papa Parse script
    // form.runScriptNamed('PapaParse');
    document.getFormNamed('Script Manager').runScriptNamed('PapaParse');

    // Receipts Feld-Ids: Zuordnung...
    // Bezahlt -> Datum
    // Kontakt -> Buchungstext manuell
    // Schlagwörter -> Buchungsart
    // Betrag in EUR -> Umsatz1
    // Einnahmen und Ausgaben -> EA-Kennzeichnung

    var datum_id = 'fld-98e4dff9f7d74050a6580f44bebf4e9a';
    var buchungstext_manuell_id = 'fld-16dda6d19d264f529e57526592e49e36';
    var buchungsart_id = 'fld-e204ad0f420845aa972d8ed527577546';
    var umsatz1_id = 'fld-289dc3baf44941b9beb8cbe14292f43a';
    var ea_kennzeichnung_id = 'fld-2fc88950003549f888369c5a99214597';

    // -------- # User dir, import file
    var user_dir = Utils.getUserName();
    var import_file_name = 'tf_receipts.csv'

    // -------- # Datumskorrekturen mit parseDate (Thx to Sam Moffatt, Brendan & Daniel Leu)
    function parseDate(dateString) {
    if (!dateString) {
    return undefined;
    }
    let pieces = dateString.split('.');
    return new Date("20" + pieces[2], pieces[1] - 1, pieces[0]);
    }

    // ------- # Import
    function Import_Entries() {
    let filename = 'file:////Users/' + user_dir + '/Documents/tapforms_dir/' + import_file_name;
    let csvFile = Utils.getTextFromUrl(filename);
    if (!csvFile) {
    console.log("No input file?");
    return
    }
    var output = Papa.parse(csvFile, {
    delimiter: ";",
    // header: false,
    });
    // # abort if there are any errors and log to console.
    if (output.errors.length > 0) {
    console.log(errors.join("\n"));
    return;
    }
    // # read each line
    for (let line of output.data) {
    // ------------- date correction
    let datum_string = line[0];
    let datum = parseDate(datum_string);
    // let conv_date = new Date(datum.getFullYear() + 100, datum.getMonth(), datum.getDate());
    if ((line[0] !== 'Bezahlt') || (typeof line[0] === typeof undefined)) {
    var newRecord = form.addNewRecord();
    newRecord.setFieldValues({
    [datum_id]: datum,
    [buchungstext_manuell_id]: line[1],
    [buchungsart_id]: line[2],
    [umsatz1_id]: line[3],
    [ea_kennzeichnung_id]: line[4],
    });
    } else {
    }
    document.saveAllChanges();
    }
    }
    Import_Entries();

    • This reply was modified 3 years, 9 months ago by Chris Ju.
    • This reply was modified 3 years, 9 months ago by Chris Ju.
    Attachments:
    You must be logged in to view attached files.
Viewing 15 results - 901 through 915 (of 2,989 total)