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 - 871 through 885 (of 2,951 total)
  • Author
    Search Results
  • 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, 6 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, 7 months ago by Chris Ju.
    • This reply was modified 3 years, 7 months 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 3 years, 7 months ago by Chris Ju.
    • This topic was modified 3 years, 7 months 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

Viewing 15 results - 871 through 885 (of 2,951 total)