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 - 811 through 825 (of 2,989 total)
  • Author
    Search Results
  • #47869
    Daniel Leu
    Participant

    Instead of separate fields, you could use a table field for your entries. There is an option to show the total at the bottom.

    I don’t use the calculation field that often. But changing the formula to this might help:

    IFNOTEMPTY(LINE TOTAL 1;LINE TOTAL 1;0) + IFNOTEMPTY(LINE TOTAL 2;LINE TOTAL 2;0) + IFNOTEMPTY(LINE TOTAL 3;LINE TOTAL 3;0) + ......

    Another option would be to use a javascript function for the calculation.

    Cheers, Daniel

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

    #47863
    Yan Cowles
    Participant

    Hi TF people,
    I’m on the trial version of TF and attempting to set up an invoice system to replace that which I was using in filemaker.
    I would like to use a Total that simply calculates the value of multiple line totals, however, if any of these are not filled in (which will usually be the case), the calculation fails.
    I can make it work if I set a default of 0 but I’d rather have unused fields left blank if you see what I mean.
    I can’t currently see a way of doing this and I really would rather avoid scripting if at all possible.
    Is there a simple solution that I’m missing, I’m not the brightest tool in the picnic box?
    TIA

    Attachments:
    You must be logged in to view attached files.
    #47862
    Richard
    Participant

    …and to close the “loop” on this one Brendan; just adding a “form save all changes” to the script sorted that update thing for me.
    THANKS!

    #47860
    Brendan
    Keymaster

    Hi Richard,

    Yes you can do that.

    On the Script Editor screen, select a field from your Table field from the Fields list on the left. Then double-click on the Child Records Loop Snippet at the bottom-left.

    Tap Forms will write the code for you that will loop through the records of the Table field and extract out the value from the selected field. Now you can write code to set those values to fields on the parent record if you like.

    Thanks!

    Brendan

    #47859
    Richard
    Participant

    Hello I was trying to plot a histogram of the averages generated by the table field. I can’t do this, but is there a way to read these values in a script, then in theory you could have these as a separate field and plot that?
    thanks

    #47801
    Bob Williams
    Participant

    This is likely just my JavaScript ignorance shining through, but I’m trying to use the Prompter class for the first time. My code works fine if I plop it into the global scope, but if I try to wrap it in a function, the variables never get filled in. I’ve also tried wrapping it inside a class method (passing this.xxx as the variables to fill in), but that doesn’t work, either.

    Here’s my code:

    // function getCopyInformation() {
    	var noteRowNumber;
    	var toRecordId;
    	var preserveSorter;
    	
    	var prompterResultHandler = function (result) {
    		if (result === true) {
    			console.log('noteRowNumber: ' + noteRowNumber);
    			console.log('toRecordId: ' + toRecordId);
    			console.log('preserveSorter: ' + preserveSorter);
    		} else {
    			console.log('Canceled');
    		}
    	};
    
    	let prompter = Prompter.new();
    	prompter.cancelButtonTitle = 'Cancel';
    	prompter.continueButtonTitle = 'Copy';
    	prompter.addParameter('Note row number: ', 'noteRowNumber')
    		.addParameter('Target record ID: ', 'toRecordId')
    		.addParameter('Preserve sorter value? ', 'preserveSorter', 'popup', ['Yes', 'No'])
    		.show('Where do you want to copy the note?', prompterResultHandler);
    // }
    
    // var destination = getCopyInformation();
    

    So run like this, it works. But if I uncomment the three commented lines, the three variables show as undefined (though result does still get set properly, so the log calls are still run).

    Any suggestions?

    #47784

    In reply to: Speed Tips?

    Stephen Meehan
    Participant

    No worries. Very minor issue.

    It’s a Form script.

    Thanks for the help, Daniel and Brendan!

    #47783

    In reply to: Speed Tips?

    Brendan
    Keymaster

    The notification to reload the records is built-in to the saveAllChanges command, so there’s no way to disable it. Not without me making changes to Tap Forms at least.

    I’ll think about providing an alternative save mechanism, one that doesn’t post the notification, in a future version.

    Is this a Field script or a Form script?

    #47778

    In reply to: Speed Tips?

    Daniel Leu
    Participant

    5s seems indeed a bit long. I added some code to measure the execution time:

    function speedtest() {
       var l1_id = 'fld-xxx';
       var l1b_id = 'fld-xxx';
       var l2_id = 'fld-xxx';
       var l2b_id = 'fld-xxx';
    
       record.setFieldValue(l1b_id, record.getFieldValue(l1_id));
       record.setFieldValue(l2b_id, record.getFieldValue(l2_id));
    
       document.saveAllChanges();
    }
    
    var start = Date.now();
    speedtest();
    var end = Date.now();
    console.log(<code>Execution time: ${end - start} ms</code>);

    The first time running the script, I get an execution time of 5ms, successive runs are all between 1ms and 2ms.

    Cheers, Daniel

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

    #47777

    Topic: Speed Tips?

    in forum Script Talk
    Stephen Meehan
    Participant

    Hi, the script below takes about 5 seconds to execute, which seems inordinately slow for something so simple.

    Anyone notice any obvious bottlenecks?

    Thanks!

    function New_Script() {

    var l1_id = ‘fld-1150255ff604464392abee526dd2592b’;
    var l1b_id = ‘fld-5afc66a3718e4ac69e5121ae0182b483’;
    var l2_id = ‘fld-b9080a9632014c118b8a4f1790d7363e’;
    var l2b_id = ‘fld-144e23e549f4475b8d384de1b6b367e3’;

    record.setFieldValue(l1b_id, record.getFieldValue(l1_id));
    record.setFieldValue(l2b_id, record.getFieldValue(l2_id));

    document.saveAllChanges();

    }

    New_Script();

    #47754

    In reply to: Table quirkiness

    Daniel Leu
    Participant

    I do something very similar. In my custom layout, I have two buttons that execute each a separate script, one to update the summary field and one to clear it. This way, the content of the table is only evaluated for the current record when I ask TF to do it.

    Cheers, Daniel

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

    #47753

    In reply to: Table quirkiness

    Bob Williams
    Participant

    Any suggestions for how I might set up my forms and/or scripts to ameliorate the saveAllChanges() selection issue caused by the refresh? When I’m trying to edit data in a table, it makes for a lot of extra moving around, and worse, I keep misstepping and accidentally entering data into the wrong cell.

    For context, I have a table with rows for notes, the fields of which include a short-notes field and a long-notes field. I have a separate script field (not in the table) that builds a summary of all the notes in the table by doing some fancy string concatenation. It’s the summary script that’s calling saveAllChanges(). Maybe there’s some way to delay the script run until focus leaves the table? Or some way I’m missing from within the script itself to grab the selection right before the save call and then restore it right after?

    #47746
    Bernie McGuire
    Participant

    Brenday
    Yes its a classic delemia :) One possibility, which I think is similar to you first approach, would be to allow one to disble the ADD function on the Employee Form in this case, and force added to be don from the Department Form.

    What I have implemented as a tempoary solution, which doesnt solve the problem , but alerts to the issue, is scripting as follows.

    On the Employee Form:
    1. a hidden auto increment
    2. the link from form for Departments field
    3. a hidden script field that does the following:
    It is triggered by a chane in the auto increment,
    it checkes if the link from field for Department is = undefined, and if it is,
    executes a Utils.alertWithMessage(“Warning”,”A an employee must have a departemnt so totals will be correct. Use the employee add from the Department Form”.

    This doesnt prevent the error but alerts the operator that additional stepes are necessary to fix the situation. It would be ideal if I could close the open Employee FOrm, deleteing the record to force the correct operation.

    If there were some way to say, pop up a Department List and let the operator assign a Department. This might be the most user friendly solution. If possible of course.

    Any time you want to knock around ideas Brendan, let me know, Im happy to engage.
    Thanks for all you hard work.
    Bernie

    #47737
    Gregory
    Participant

    Also, a possible related bug: when I first wrote the script and ran it, I was getting syntax errors about one of my opening vars being defined more than once (“Can’t create duplicate variable”).

    the reason you’re getting this error is because your variables are being declared in the global space. if you’ve declared one or more of these variables in other scripts that have already run, you’ll get this error.

    any variable declared outside of a function block will be global. to minimise these situations, I would reformat the script so that none of the variables are global:

    function areThereOpenTodos() {
    
       var todosTableId = 'fld-cacbf';
       var todosTable_doneCbFieldId = 'fld-b94f8';
       var todosTable_ofFieldId     = 'fld-4f82e';
    
        var countDoneChecked = record.getTotalOfLinkedFieldForField(todosTableId, todosTable_doneCbFieldId);
       var countOfChecked = record.getTotalOfLinkedFieldForField(todosTableId, todosTable_ofFieldId);
    
       return (countDoneChecked + countOfChecked) > 0;
    }
    
    function run() {
    
       var openTodosFieldId = 'fld-f1892';
    
       if (areThereOpenTodos()) {
          record.setFieldValue(openTodosFieldId, 1);
          console.log('set to 1');
       } else {
          record.setFieldValue(openTodosFieldId, 0);
          console.log('set to 0');
       }
    }
    
    run();
    #47726

    In reply to: Table quirkiness

    Bob Williams
    Participant

    If I haven’t right-clicked on a table column and selected either of the sort options, the table visually shows that no sort order is being applied: the column header is gray, and the sort direction triangle is hollow. As soon as I choose a sort option from the context menu, both of those things change, showing that a sort order has been applied and what that order is.

    From a user POV, this suggests that there simply is no sort being applied before selecting one. In such case, I’d expect the rows to remain in the order I entered them, and it’s this order that I’m referring to as the “natural order”.

    I get that deep under the hood, the database itself my treat sort order in the absence of an explicit sort as undefined, but that feels like an implementation detail that shouldn’t leak all the way up to the user level of an app like this. As a general rule, things should stay where the user put them and not move around on their own. In this case, it’s akin to unsorted rows in a spreadsheet arbitrarily reordering themselves — that would be a maddening experience, and no spreadsheet has ever worked that way.

    A date field (or an auto-increment field, which I also played with as a solution) is a decent workaround, but it’s more noise in the user’s system that they don’t directly need, and it’s more hassle to set up and maintain. As a suggestion, I think TF should track natural order internally and maintain that order unless the user chooses otherwise. This will also enable an “insert row here” feature, which doesn’t logically make sense in the current model.

    As to the changing selection issue, some more testing suggests that it’s related to a script field on the form, specifically, the document.saveAllChanges(); line. Note that the script doesn’t change the table in any way; it simply iterates over the table and outputs a summary. If you need more, let me know and I’ll send you my file.

Viewing 15 results - 811 through 825 (of 2,989 total)