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 - 2,551 through 2,565 (of 2,935 total)
  • Author
    Search Results
  • #33786
    Kirk Williams
    Participant

    Thanks so much, Bendan – this is super helpful! One thing I neglected to mention is that the URL prefix is actually entered into a field on the form (since WordPress insists on creating monthly directories for uploaded images, I change the default value of this field at the beginning of the month). With that in mind, I replaced the static text in your code with a reference to the ID of the “image_prefix” field.

    The prefix seems to be working, but I’m still not getting the filename. It’s referencing a TypeError on line 9; I am going to continue to tinker and see if I can determine where I’ve thrown off the script.

    Once I get this working, my next challenge will be to include data from the other photo fields (“photo1”, “photo2”, “photo3” and “photo4”). Your code to append the comma for all but the last item is very cool!… I guess it’s time to start brushing up on my Java lol!

    Thanks again for your time – I will keep you posted on my progress.

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

    Hi Kirk,

    You can accomplish what you want by using a Script field instead of a Calculation field.

    In Tap Forms, a Photo field is represented by an array of dictionaries that looks like this:

    [
          {
            "dimensions" : "{2048, 1536}",
            "filename" : "terminator-jugement-day.jpeg",
            "mimetype" : "image/jpeg"
          },
          {
            "mimetype" : "image/jpeg",
            "dimensions" : "{1280, 960}",
            "filename" : "hunger-games.jpeg"
          },
          {
            "mimetype" : "image/jpeg",
            "dimensions" : "{4032, 3024}",
            "filename" : "the-martian.jpeg"
          }
    ]

    Each of the things above are a dictionary that contains the mime type, the dimensions of the original image stored in Tap Forms, and the original filename.

    In a Script field you could have Tap Forms return a list of these images prefixed by a specific URL if you like.

    You would need to first get the value for the Photo field — which will be in the format like the above sample, then loop through the array picking out the filename from each Dictionary. A Dictionary is just like what you see above where there’s a key and a value. The key you want is filename and the value will be whatever the value is (e.g. the-martian.jpeg).

    Here’s some Script Field code which will do exactly what you need:

    function Photo_Links() {
    
    	var photo_field_id = 'fld-e2cf02f376864a7cb9f090e4a597f3e4';
    	var photos = record.getFieldValue(photo_field_id);
    	var links = "";
    	var link_prefix = 'http://mywebsite.com/wp-content/uploads/2019/02/';
    	
    	for (var index = 0, count = photos.length; index < count; index++){
    		var photo_data = photos[index];
    		var filename = photo_data['filename'];
    		links = links + link_prefix + filename;
    
                    // append a comma at the end of the link only if this is not the last link
    		if (index < photos.length - 1) {
    			links = links + ",";
    		}	
    	}
    	return links;
    
    }
    
    Photo_Links();

    You could just copy and paste the above into a Script Field in your form and then just modify the photo_field_id to match the ID of your own Photo field and the link_prefix to use the correct URL.

    Let me know if that works for you.

    Thanks!

    Brendan

    #33783
    Kirk Williams
    Participant

    Hello all,

    New user here – a bit of a learning curve for me as a relatively new Mac user, but I definitely appreciate the potential of this app. I’m still a bit stumped with one form in particular (that was the primary reason for me purchasing TF).

    I am currently using AirTable for inventorying my late father’s model train collection. In the interest of efficiency, I am using that same AirTable data to export my data into a WordPress website (Woocommerce shop via CSV). I am rapidly approaching the limit threshold of my free AirTable account, so I’d like to migrate this data into tap forms.

    The field with which I am hitting a roadblock is the “Product Images”. I’ll try to describe this field without being too verbose:

    Each record in this collection includes one or more photos. These photos are added to my Airtable, and also (as a completely separate process) uploaded to the WordPress site. Once uploaded, the photo(s) can be referenced using their original filename, preceded by the site’s URL and directory structure. The end result resembles “http://mywebsite.com/wp-content/uploads/2019/02/filename.jpg&#8221;.

    Using Airtable, I have created a formula field (the equivalent to Tap Form’s calculation field afaik) that assembles the URL by combining the URL prefix (which I enter as static text in a separate field) and the filename of the photo. I have multiple photo fields, so none have more than one single image attached. “IF” arguments are used in the formula field to prevent blank cells from returning just the URL prefix. The end result is a calculated field containing a comma-separated list of each photo’s filename preceded with the URL.

    I feel that this mechanism could be replicated using Tap Forms, however, the hurdle I’ve yet to overcome is how to extract the photo filename into a calculation. It seems it can be done AFTER an export using the CSV data, but I’d prefer to be able to process this field within the app so that my exported file can be immediately used to import data to the website.

    If anyone can offer guidance as to if/how I can accomplish this task within Tap Forms, I would be extremely grateful! Please note I have virtually zero JS scripting knowledge, but I’d be willing to take a crack at it if scripting is the only option. For reference, the arguments from my AirTable calculation are:

    {WC Featured Image}&IF({WC Gallery Image 2}=BLANK(),BLANK(),”, “&{WC Gallery Image 2})&IF({WC Gallery Image 3}=BLANK(),BLANK(),”, “&{WC Gallery Image 3})

    Thanks in advance for any insight!

    Best,

    Kirk

    #33772

    In reply to: Loop over records

    Brendan
    Keymaster

    Hi James,

    It sure can.

    Tap Forms will even write the code for you.

    Open up the Script Editor for your form that has the Table field. Then select a field within your Table field from the left side list of fields.

    Then find the Child Records Loop snippet at the lower left. Double-click on it and Tap Forms will write the code for you to loop over the records of the Table field.

    Hope that helps!

    Brendan

    #33771
    James Hayes
    Participant

    Can a script be used to loop over all records in a table?

    #33680

    In reply to: Inventory & Orders

    Brendan
    Keymaster

    Well, from the Invoice tracking document perspective, I’m thinking you would have the Quantity Available on the Product form. Then when you choose a Product and enter a quantity, you want that quantity to be subtracted from the Product’s quantity? Although it sounds like a simple thing, it’s a bit tricky. You would definitely need JavaScript to do that work for you.

    When you changed the quantity of the selected product, you would need a script that would fetch the product record, then update its Quantity on Hand by subtracting the value you just typed in.

    The problem right now though is I haven’t written an API to let you directly search a form for a specific value in a specific field (e.g. a product number). You can search the products in a for loop though, getting every product and looking at the value for the field to see if it matches the selected product number. But depending on how many products you have, it could slow things down. Although you would short circuit the loop once you’ve found the right product. It’s still not super efficient if the product you’re looking for happens to be the last one in the list.

    Once you’ve found the matching product to the one you selected, you’d just update it’s Quantity on Hand. In the Orders form, Tap Forms has a Table field that lists the selected Product records. The values for those entries are there by copying the values from the Product form. They’re not directly linked to the Product form in any way.

    It’s certainly doable. But would just take some work to write a script to do what you need.

    Hopefully you’ve got some JavaScript skills :)

    Thanks,

    Brendan

    #33678

    In reply to: Inventory & Orders

    Phil Lee
    Participant

    Thanks! That is a great starting point. I am trying to figure out how to then calculate the total number of each item ordered and subtract that from a quantity of the items received… Not sure if a script would be needed or if I am missing something obvious…

    #33669
    Brendan
    Keymaster

    The Location field value is just a dictionary. So you need to make a new dictionary object in JavaScript before you set the values on it. Essentially you’re getting a null value back from getFieldValue(). If you get a null value, then you just create an empty dictionary and then your code should work.

    var location = {};

    #33662

    I have a suble script problem:
    I want to create an artificial location field value.

    I wrote this little script:

    function SetCoordinates() {
    
    	// Durch eigenen Code ersetzen
    	var coord_id = 'fld-65d2a762b14542f9abbca1d521df2e37';
    	var title_id = 'fld-692eb15910f7433181f8f8a6b2fceccc';
    	var gps_lon_id = 'fld-4a453e4f44854f0f893d3e275d4342c4';
    	var gps_lat_id = 'fld-4dfd053afaec40b58395083e694085ac';
    	var location_value = record.getFieldValue(coord_id);
    	location_value["title"]= "GST " + record.getFieldValue(title_id);
    	location_value["lon"]=record.getFieldValue(gps_lon_id);
    	location_value["lat"]=record.getFieldValue(gps_lat_id);
    	record.setFieldValue(coord_id, location_value);
    }
    
    SetCoordinates();

    If the field coord_id has already a value this works.
    If it has no value (such es no one pressed the location icon before) this doesn’t work. How can I create an empty data structure of the type location?

    Thanks for hints

    #33633

    In reply to: Script: object TFField

    This script:

    var t = form.getFieldNamed(‘P1’);
    console.log(t.name);
    console.log(t.fieldType);
    console.log(t.fieldDescription);
    console.log(‘eoj’);

    This is the console panel

    undefined
    undefined
    undefined
    eoj

    In the Form there is a P1 field.
    What’s wrong?

    #33627

    In reply to: Script: object TFField

    Thanks.
    Can you add a property field_id?

    For make indipendent scripts From Forms, and indipendent by database, i need a function like this:

    Form.getfieldid(‘name Of field’);
    And return the field_id ‘fld…’ without open snippets.

    Gianantonio

    #33628

    In reply to: Script: object TFField

    Thanks.
    Can you add a property field_id?

    For make indipendent scripts From Forms, and indipendent by database, i need a function like this:

    Form.getfieldid(‘name Of field’);
    And return the field_id ‘fld…’ without open snippets.

    Gianantonio

    #33618
    Brendan
    Keymaster

    There’s no scripting support for adding to the Calendar.

    The very first field in your form is what’s used to generate the default Title value. You can edit the title value of course before clicking the Add to Calendar button. The link to the record is also added to the calendar.

    #33617

    In reply to: Script: object TFField

    Brendan
    Keymaster

    Hi Gianantonio,

    Right now the only things exposed are the name, fieldType, and fieldDescription properties.

    I updated the JavaScript API to document the new APIs I added:

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

    #33612

    In reply to: Custom layouts in iOS

    Graeme Sheppard
    Participant

    I just wanted to register another request for custom layouts in iOS.
    I’m getting by for my use case by creating scripts to summarise information, which is a fantastic ability, but it’s a bit fiddly and not for everyone.

    I do love the scripting, though.

Viewing 15 results - 2,551 through 2,565 (of 2,935 total)