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 - 1,456 through 1,470 (of 2,989 total)
  • Author
    Search Results
  • Sam Moffatt
    Participant

    Script fields in tables seem bugged but I did this in a test and it worked in the script editor:

    function Percentage() {
    	var per_serving_amount = record.getFieldValue('fld-3fead523555c48f9a77377fd340e59f6');
    	var total = record.parentRecord.getTotalOfLinkedFieldForField("fld-b9927271feeb4fe2b9c0cd32f36c7cd1", 'fld-3fead523555c48f9a77377fd340e59f6');
    	return (per_serving_amount / total * 100);
    }
    
    Percentage();
    

    Where per_serving_amount or fld-3fead523555c48f9a77377fd340e59f6 is a field inside my table and where fld-b9927271feeb4fe2b9c0cd32f36c7cd1 is the field ID of the table in the main form. It gives me the right value in the script editor but it feels like script fields are not being properly evaluated in table fields.

    Alternatively if it was possible to project parent fields into the table calculations, I created a calculation field in the parent record with the total of the field int he table however I couldn’t readily get to it via a calculation in the table.

    Brendan
    Keymaster

    You would need to use a Script field for that and ask the form for the total of the field from the Link to Form field.

    You would need to loop through all of the records of the Table field and total up the value of that column. This would be done whenever the value in your Quantity field changes.

    #43781
    Ray Robillard
    Participant

    Hi !

    I’ve a movie database in which there’s a Tag pick list, made of checkboxes. I want to find how many different records have a certain item in this pick list checked.

    So thinking the pick list returned something I wasn’t sure of, I tried to get the type of the object, but all I am getting is undefined.

    var value = movie_form_records[index].getFieldValue(movie_form_tags_id);
    console.log(typeof value);
    (console output is “undefined”)

    So when I try this :
    var pos = value.search(“Feel good”);

    It never returns any item, despite the fact that some of the records have this tag. I know this because using the search filter, I can find several movies for which this tag is checked.

    My loop goes through all the records and make the following test :
    if (pos >-1) {
    nombre++;
    }

    But when I am running the code, I am getting the following output in the console :

    2021-03-10, 8:17:57 AM / Movies / Feel good
    Feel good: TypeError: undefined is not an object (evaluating ‘value.search’), line:(null)
    Feel good: TypeError: undefined is not an object (evaluating ‘value.search’), line:(null)

    The whole code is :

    function Feel_Good() {

    var nombre = 0;
    var movie_form = document.getFormNamed(‘Movies’);

    var movie_form_tags_field = movie_form.getFieldNamed(‘Tags’);
    var movie_form_tags_id = movie_form_tags_field.getId();

    var movie_form_records = movie_form.getRecords();

    for (var index = 0, count = movie_form_records.length; index < count; index++) {

    var value = movie_form_records[index].getFieldValue(movie_form_tags_id);

    var pos = value.search(“Feel good”);

    if (pos >-1) {
    nombre++;
    }

    }

    return nombre;
    }

    So.. what am I doing wrong ? I’m a total newbie at JavaScript. So maybe I missed something somewhere.

    Thanks,

    Ray

    scott johnson
    Participant

    So what I’m looking to do is re-build an old formulation database i built years ago in Access – where i’d have a large ingredient table with hundreds of ingredients (sugar, fats, etc – and each one of those had all their nutritional attributes stored in that same record).

    There was a second table then, which had a number of drop down fields that linked back to the ingredient table – allowing me to select each individual ingredient for use in the formulation. I’ve been able to get this far in TapForms on my own.

    Where I’m stuck is here: When i pull – say – sugar – from the drop down list that’s linked back to the ingredient table – what i’d also like it to do is pull and display the information for, say, carbohydrates – that is associated with the sugar i just choose. Why? Because I will then use that in a series of calculated fields to determine the quantity of carbohydrates in the precise formulation i’m working on, and get real time updates. This is what’s got me stuck. I’m not a scripter – so that’s out of my depth. Anything obvious I’m missing to help me do this?

    Thanks folks
    SJ

    #43733

    In reply to: Create Running Totals

    Sam Moffatt
    Participant

    If you’re after running totals, a while back I did a post on a bank account style running total. There are some caveats which I’ve posted about elsewhere around making sure your ordering is consistent otherwise the numbers will be wrong. Excel has an implicit row ID in it where as Tap Forms does not, so if you don’t have a field you can sort on consistently then you will need to add your own row number (perhaps by using an autoincrementing number field).

    #43728
    Daniel Leu
    Participant

    Hi Gerhard,

    You can use the progress feature for that, but this seems to be an overkill for such a simple task. Following script does the same thing:

    function setAddress() {
    	const adresse_lang_id = 'fld-xxx';
    	const maps24_id = 'fld-xxx';
    
    	for (r of form.getRecords()){
    		let x = r.getFieldValue(adresse_lang_id);
    		r.setFieldValue(maps24_id, x);	
    	}
    	document.saveAllChanges();
    }
    
    setAddress();

    But I’m wondering if using a form script for this tasks is what you really want. Whenever you run the script, all your maps24 field are updated.
    It might be better to use a field script for that.

    function setAddress() {
    	const adresse_lang_id = 'fld-xxx';
    	const maps24_id = 'fld-xxx';
    
    	let x = record.getFieldValue(adresse_lang_id);
    	record.setFieldValue(maps24_id, x);	
    	document.saveAllChanges();
    }
    
    setAddress();

    Now the target field is only updated when the adresse_lang field is changed.

    Cheers, Daniel

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

    #43721
    Gerhard Hoffmann
    Participant

    Hi Eddy,

    I’m using TabForms since 4 months and the script is a real game changer. I’m not an expert in script programming, but my son helped me a lot.
    I had a similar problem and I want to fill in the address fields to the field location, but not only to one address, it should do the work to all addresses. See, we use a for-next-loop.

    // start

    var adresse_lang_id = ‘fld-5840ffe2e4b04f01a150329d15498877’;
    var maps24_id = ‘fld-ce41104cdbc2405eb2ad0f9be8baa35a’;
    var progress = Progress.new();

    function ProcessRecords(records) {
    for (index in records) {

    if (progress.cancelled) {
    console.log(‘Cancelled operation’);
    break;
    }

    var aRec = records[index];
    var x = aRec.getFieldValue(adresse_lang_id);
    aRec.setFieldValue(maps24_id, x);

    progress.updateProgress(index);
    }
    }

    var records = form.getRecords();
    progress.totalCount = records.length;
    progress.currentCount = 1;
    console.log(‘Begin’);

    // show the progress sheet
    progress.show(‘Processing Records…’);

    ProcessRecords(records);

    // dismiss the progress sheet when done.
    progress.dismissProgress();

    // save your changes
    form.saveAllChanges();

    console.log(‘End’);

    // end

    Regards,

    Gerhard

    #43713
    Eddy
    Participant

    Hi Sam!

    Thanks a lot.

    But I am afraid, this is not really, what I need and search for.

    Actually I need a way, that fills in the geocoordinates automatically according to the address-date I wrote in by my script.

    Hope, now I express myself better. Sorry for any confusion.

    Regards, EDDY

    #43710
    Daniel Leu
    Participant

    I’ve never used the location field, so I’m not familiar with it.

    But in your script, you are missing a document.saveAllChanges(); after setting the location field. If you click on Refresh records list, all records should be updated and the location saved.

    Cheers, Daniel

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

    #43708
    Eddy
    Participant

    Hi Folks!

    QUESTION:

    How can I force the location field to look automatically for the geocoordinates without opening it manually?

    CASE

    We need a to have an overview of our clients on map view. But it would be to much work to fill the location field manually. So, I have a little script, that fills the location field based on the data in the adress fields.

    function FILLING_locationfield() {
    
    var ADR_street = record.getFieldValue('fld-a2…');
    var ADR_postalcode = record.getFieldValue('fld-b7…');
    var ADR_city = record.getFieldValue('fld-e6…');
    var ADR_country = record.getFieldValue('fld-b9…');
    
    var TARGETFIELD_locationfield_id = 'fld-01…';
    
    var ADDRESSDATA_for_locationfield =	
    ADR_street + ", " + ADR_postalcode + " " + ADR_city + ", " + ADR_country ;
    
    record.setFieldValue(TARGETFIELD_locationfield_id, ADDRESSDATA_for_locationfield);
    }
    function FILLING_locationfield();

    The problem is: This is filling the location field properly with the adress data. But in order that the location field is getting the fitting geocoordinates, I have to click on each adressfield manually and then to click on the save button.

    So: How can I force the location field to look automatically for the geocoordinates without opening it manually?

    Thanks in advance for any help.

    Stay healthy, EDDY

    #43703
    Sam Moffatt
    Participant

    Correct, the standard built in Javascript engine works within the scripts.

    If you check out my repo there is a match example and a replace example (also includes a sample of creating a RegExp object as well if you look up a few lines).

    #43702
    Brendan
    Keymaster

    I imagine you can just use the regular JavaScript regular expression support:

    https://www.w3schools.com/js/js_regexp.asp

    But I haven’t tested it myself.

    #43699
    Victor Warner
    Participant

    I have a text field. It contains names (usually two or three words).

    Is it possible to extract only the first word in a script field in way using regular expressions? (eg ^(\S+) (.*)$ or ^(.+?) (.*)$).

    Brendan
    Keymaster

    I’m glad you were able to figure it out.

    The trigger mechanism is that if you have a call to getFieldValue(some_field_id) in a Script field, Tap Forms will execute the script whenever the value of some_field_id is changed.

    Sam Moffatt
    Participant

    I’m seeing the same thing, the results just aren’t showing up in the table. Here’s my test script:

    "Hello, World";
    

    Works fine in the script editor but never shows up in the table. I do believe we’ve found ourselves a bug!

    Quick idea: have the script editor show the parent fields like a link to form style relation but instead automatically inserting the record.parentRecord.getFieldValue as the code completion.

Viewing 15 results - 1,456 through 1,470 (of 2,989 total)