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 - 976 through 990 (of 3,053 total)
  • Author
    Search Results
  • #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 4 years ago by Chris Ju.
    • This reply was modified 4 years ago by Chris Ju.
    Attachments:
    You must be logged in to view attached files.
    #47091
    Brendan
    Keymaster

    Ok, well this kind of works, but it’s not great:

    function Script() {
    	var first_name = record.getFieldValue('fld-b955dffe477c494db26f60faf1dd9a75');
    
    	var parent_field_id = 'fld-208116bc2576460da36cee99b12e3c04';
    	
    	var parent_field_value = record.parentRecord.getFieldValue(parent_field_id);
    	
    	return parent_field_value;
    
    }
    
    Script();

    In this form I have a Table field with 3 fields in it. A First Name field and a Last Name field and a Script field.

    The first line to get the field value from the Table field’s record is only there to trigger the script to execute when the First Name field is modified. It’s not doing anything with the value.

    The trick is record.parentRecord.getFieldValue(parent_field_id);

    But Tap Forms won’t trigger the Script field to execute if you modify the parent form’s field. I think that’s probably why I didn’t document this. The parent form would have to loop through all Table fields looking for scripts that reference the parent form’s field and then execute the scripts. Just hadn’t really flushed the coding out for that I guess.

    #47090
    Daniel Leu
    Participant

    Can you share the script you are using or a test case to reproduce this?

    Cheers, Daniel

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

    #47085
    Chris Ju
    Participant

    Hello,

    since the last Tap Forms update, the import from CSV files with the PapaParse script leads from short dates dd.MM.22 to dd.MM.1922. For example, the German date 12.04.22 becomes 12.04.1922 on import. It should be 12.04.2022. That wasn’t a problem in the last version.

    Does anyone have an idea to solve this issue without splitting the date and adding 100 to the year? This would lead to an error if the year in the date is really 19xx.
    e.g.:

    
    ...
    let datum_string = line[0];
    let datum = parseDate(datum_string);
    let conv_date = new Date(datum.getFullYear() + 100, datum.getMonth(), datum.getDate());
    ...
    

    BTW: Copy&Pasting the short date from the CSV file to the date field works fine.

    Thanks in advance.

    Chris

    • This topic was modified 4 years ago by Chris Ju.
    • This topic was modified 4 years ago by Chris Ju.
    #47084
    Brendan
    Keymaster

    Hi Bernie,

    You would have to use a Script for this function.

    There’s a function designed for getting the maximum value, but it only works for Number fields right now:

    var max_value = record.getMaxOfLinkedFieldForField(linkedFieldID, fieldID);

    But you could loop through the linked records manually and pick out the largest date value.

    Sorry it can’t be done with a Calculation field though.

    Here’s an example script that would do what you want:

    function getMaxDate() {
    
    	var orders_id = 'fld-41443e967b3c4bdd8e258eabef7ffc8c';
    	var date_id = 'fld-3604363a4c07424294113852f4b3651e';
    	
    	var orders = record.getFieldValue(orders_id);
    
    	var largest_date;
    	
    	for (var index = 0, count = orders.length; index < count; index++){
         	var date = orders[index].getFieldValue(date_id);
         	
    		if (date) {
    			// do something
    			if (largest_date == undefined || largest_date.getTime() < date.getTime()) {
    				largest_date = date;
    			}
    		}
    	}
    	
    	return largest_date;
    }
    
    getMaxDate();

    You would need to replace the fld-.... parts with the field IDs of your own fields though.

    #47079
    Daniel Leu
    Participant

    Thank you for sharing your form template. When you use record in a field script inside a table, you are referring to that row in the table and not the overall record anymore.

    I don’t think that there is a way to get to the main record from the table field script. How about moving the intensity calculation to the main record and update the table’s intensity field from there?

    Cheers, Daniel

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

    #47075
    Anonymous
    Inactive

    Thank you.

    The table has 4 columns, Set, Reps, Weight and Target Weight and the Id of the table is fld-f59e078819e24d2aa1492d36d8fe268c.

    The situation is the following:

    1. The form contains a field F that is not a table and a field that is the table T.

    2. The table T contains a column T_s of type script.

    3. For any given record I want to have access to the value of field F inside the script that pertains to T_s.

    If I run the following code inside T_s’ script (fld-f59e078819e24d2aa1492d36d8fe268c is the Id of the table)

    
    var table_field_id = 'fld-f59e078819e24d2aa1492d36d8fe268c';
    
    var testrecords = record.getFieldValue(table_field_id);
    	
    console.log(testrecords.length);
    		
    var testvalues = record.values;
    		
    console.log(testvalues.length);	
    

    I get the output:

    
    11.04.22, 18:44:59 / Sets Old / Target Weight
    0
    undefined
    

    I’am new to Tap Forms 5. Maybe missing some fundamental stuff here?

    Cheers

    #47073
    Anonymous
    Inactive

    Hello everybody,

    I like to access the record of a Form F that has a table field T from inside a script field inside T. If I use record.values I get a dictionary of the form

    {"Id of table field 1" = value of table field 1; 
    "Id of table field 2" = value of table field 2; …  }

    .

    But I need to access the value of a specific field of F from inside the script field of the table field T, i.e I need a dictionary of the form

    {"Id of field 1 of F": value of field 1 of F;
    "Id of field 2 of F": value of field 2 of F; …}

    .

    Is this possible?

    Cheers

    #47070
    Bernie McGuire
    Participant

    This is such a basic question, Im sure it’s been asked but I can not find the answer.
    For Example Main Form is a Customer
    Linke form is list of orders

    I want to show the latest order date, from the order form , on the Parent Customer Form. So I can see it on the Record list for the Customers.

    Oh, yes. I am using a JOIN relationship which is working perfectly.

    I can not find a way to get the ‘MAX’ date in a Calculated field. I prefer to not use scripting .

    I am using IOS (I do have Mac also)

    Please any help is appreciated.
    THanks Bernie

    #47059
    Brendan
    Keymaster

    Hi Juan,

    This does not require a script for that (since you posted in the Script Talk forum). You can just go to the Options tab on the Print panel and turn off the date, time and page number options.

    Thanks!

    Brendan

    #47050
    Sam Moffatt
    Participant

    I forget that dealing with dates in JS is so weird at times, I went looking and found a decent looking strftime port and threw it in my script manager repo as well.

    #47030

    In reply to: Help with a script

    Stig Widell
    Participant

    Sam again,
    After having explored a bit further, this is the situation:
    The script Kalva works fine with 2 of the breeding bulls (1 & 4)
    It doesnt work with 3 (the rest) of the breeding bulls (1, 3 & 5)
    I then get the message in MAC “Varning Det gick inte att hitta posten!”
    I cant figure out why some bulls work and not the others.

Viewing 15 results - 976 through 990 (of 3,053 total)