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,696 through 1,710 (of 2,952 total)
  • Author
    Search Results
  • #41799
    Arthur Maccabe
    Participant

    Thanks. I’ve been busy updating my database — migrating from the original many-to-many, to a pair of many-to-one’s with the intermediate joins. I ended up writing a script to create the join records and then built the links by hand.

    One thing that I’ve noticed is the calculated fields don’t seem to update — I have to re-save the calculation to force an update. Is this common, or have I done something wrong?

    #41794
    Sam Moffatt
    Participant

    If you jump into the script editor and look through the snippet list, you’ll find the “Child Records Loop” snippet. If you select the linked field you’re looking to render into the other form, it’ll put in a bunch of place holder text (delete the basic boilerplate Tap Forms gives you). I just did this on a post, it looks like this:

    function recordsLoop() {
    
    	var topics_id = 'fld-fae59d1ee3184c4cbec2eac87aeaa9ae';
    	var topic_title_id = 'fld-fce83c065b174df1919ada0de6e0551e';
    	var topics = record.getFieldValue(topics_id);
    
    	for (var index = 0, count = topics.length; index < count; index++){
         	var topic_title = topics[index].getFieldValue(topic_title_id);
    		if (topic_title) {
    			// do something
    		}
    	}
    	return;
    }
    
    recordsLoop();

    If you wanted to make a comma separated list of all of the values, the // do something needs to gather together the values. To do this add var returnValue = []; after the other line that has var topics on it, it’ll create an array we’ll use to collect values. Then change // do something to be returnValue.push(topic_title); which will add the values to the array. Then finally change the line that has return; on it to be return returnValue.join(', '); to give you a comma separated value. The final form should look like this:

    function recordsLoop() {
    
    	var topics_id = 'fld-fae59d1ee3184c4cbec2eac87aeaa9ae';
    	var topic_title_id = 'fld-fce83c065b174df1919ada0de6e0551e';
    	var topics = record.getFieldValue(topics_id);
    	var returnValue = [];
    
    	for (var index = 0, count = topics.length; index < count; index++){
         	var topic_title = topics[index].getFieldValue(topic_title_id);
    		if (topic_title) {
    			returnValue.push(topic_title);
    		}
    	}
    	return returnValue.join(', ');
    }
    
    recordsLoop();

    You can pull in multiple fields as well by following the same convention. If you click on the field you are interested in and then click on “ID”, it’ll generate the var field_name = 'field-id'; code for you. You can also double click on a field on the other side of the link and it’ll generate something like the topics[index].getFieldValue line with the field ID embedded into the generated code.

    If newlines are more your thing, change returnValue.join(', ') to returnValue.join('\n'). If you want to go a little more advanced in your formatting, using the script to update the new Markdown field will give you more programmatic control over formatting.

    #41791
    Mark Rudolphi
    Participant

    Sam

    You mentioned

    “1. If you’re on the child side of a 1:M relationship, it should be showing you a cut down view of the linked record. If you’re on the parent side or using a M:M relationship, you need to use a script field to aggregate the values and display them.On the desktop it would display a table for you but on mobile a script field is probably your best bet.”

    Can you give me an example of what this script might look like or point me in the direction of where to learn? Thanks so much

    Mark

    #41790
    Sam Moffatt
    Participant

    One more thing to help you on the journey, here’s a link to creating a script that will automatically count the number of child records. If you go with the above advice, you’ll need to update the script to look at each side (one for author and one for books) and it’ll automatically set the value as you create them into a corresponding field. Obviously you’d need to change the field ID’s over and what not. It’s not foolproof but it generally works for me. There is a follow up post that goes into details about what the script is doing and why.

    It’s derived from my own use with order to order item/line item that auto creates the line item number.

    #41778
    Arthur Maccabe
    Participant

    I have a similar problem that I’m trying to work through. I have a collection of books and a collection of authors. I want to keep track of all of the books for an author and I also want the authors for a book ordered by something other than their names. If I use a table for the authors of a book, it looks like I will need to write a script that builds the inverse relationship for each author.

    Alternately, I could use the many-to-many relationship between authors and books, and add a table for each book, that duplicates the author list, providing the ordering I want.

    Neither seems ideal. Are there other ways to approach this?

    Thanks!

    #41768
    Sam Moffatt
    Participant

    For the many to many link type, there was a quirk where the “show inverse relationship” needed to be toggled to reset the field on the other side of the link but that will let you map many to many on both sides.

    1. If you’re on the child side of a 1:M relationship, it should be showing you a cut down view of the linked record. If you’re on the parent side or using a M:M relationship, you need to use a script field to aggregate the values and display them. On the desktop it would display a table for you but on mobile a script field is probably your best bet.

    2. The experience on iOS here is a little awkward because of where the various buttons end up and the hint text pushes towards adding a new value rather than selecting an existing value. I don’t think there is a good way around this one.

    3. Linked fields mess with sort and search because the linked field itself has multiple fields and if it’s a multiple relation you have multiple records as well. The solution is again to use and have that flatten the records for you. Then the search and sorting can be done on the script field once you’ve extracted the value that works for you. If you are in a 1:M relationship, the child record can use a calculation field to extract a field from the parent easily.

    4. For the pick list what you could do is have a script field enforce that the value exists and resets the vendor field if an invalid item is entered and then pops up an alert to the user. That’s a reasonable amount of scripting but also doable as an extra validation step.

    #41766
    Daniel Leu
    Participant

    I just discovered that TapForms does have script buttons! But only for mac as it’s part of the custom layouts feature.

    Sorry, I didn’t mention this since your example image was for the iPhone and custom layouts are not supported on mobile.

    Cheers, Daniel

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

    #41764
    cf
    Participant

    I just discovered that TapForms does have script buttons! But only for mac as it’s part of the custom layouts feature.

    screenshot

    Bringing this into the default layout for mobile would be amazing!

    #41758
    cf
    Participant

    I should clarify that my request for a “button” field type can essentially be restated as “make scripts more easily accessible when viewing a record details screen on iOS”. Unlike the records list screen where favorite scripts can be more easily surfaced (ad Daniel Leu pointed out), the details screen requires more taps to get to the scripts, and the popup form is harder to thumb-reach than the action sheet.

    That said, in my opinion the best way to trigger scripts on the record details screen is to offer a button/action field type. This gives us the flexibility to decide which scripts should be easily triggered and even lay it out in the field as desired (and even use other scripts to show/hide the button like any other field).

    I really think that a button field type that triggers a script can have wide-reaching implications for what kind of powerful work flows can be enabled in tap forms with very little effort.

    #41757
    cf
    Participant

    There is already a button where you can favorite scripts. This button doesn’t appear if you don’t have a script marked as favorite…

    Thank you for the suggestion. Yes I have seen that this is possible but as you mentioned this does require more interaction than just having a button right there in the form. Additionally it’s more setup, having to create a script for each action record.

    As far as the prompter goes it doesn’t seem offer a way to select from a list of actions, seems like the inputs on the prompter are fairly limited. In any case a prompter would also be more than just one-tap and go.

    To clarify the relative dates thing, you want a formatter to display as “18 days ago” or similar?

    Yes, rather than requiring the use of a script to accomplish this I feel like a formatter is a better solution. It is actually supported natively in iOS (see RelativeDateTimeFormatter here and here). This would allow the actual data value backing the row to remain unchanged, only having the formatter used for rendering the date/time.

    #41756
    Sam Moffatt
    Participant

    I haven’t seen #1 on your issues list but I’ve seen issues where it doesn’t launch the right document from cold start (though I’m not sure I’ve seen it recently, I usually make sure TF is warm and on the doc I want) and I have seem sometimes scripts don’t execute at all. That’s a new quirk!

    To clarify the relative dates thing, you want a formatter to display as “18 days ago” or similar?

    I’d also like the ability to set a default value on location fields to default to set current location just like you can default the date fields to set current date. Getting it via a script would be good as well but having it as default would alleviate some of the pain as I feel it could safely run in the background and set the field value once it’s stable.

    #41751
    Daniel Leu
    Participant

    1 A new “button” field type that runs a script for that specific record.

    There is already a button where you can favorite scripts. This button doesn’t appear if you don’t have a script marked as favorite… For the least amount of GUI interactions, create a script for each activity and mark them as ‘favorite’ in the options inside the script editor. Obviously you could use the prompter feature and just use one script. But then you have one more ‘click’ to do.

    Yep, if there is only one script, it would be nice if it is directly executed.

    Cheers, Daniel

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

    #41740
    cf
    Participant

    I just recently started using TapForms and this is amazing. I can’t believe this app isn’t better known. I’ve tried many different options for organizing my information (Notion, Coda, AirTable, MyBase, and many more) and none come close to the functionality I wanted or in many cases their performance was terrible. TapForms hits the right balance of capability and simplicity.

    When did I...? screenshot

    TapForms is beginning to replace multiple apps with its flexibility. One example is an app called “When did I…?”. The premise is simple, it just has a list of actions on the main screen, like “walked the dog” or “washed the car” etc… and you tap one of the rows to log that action (see screenshot above). That’s it. I was able replicate this functionality in TapForms with two tables and a script:

    The first table is a list of actions which includes a field that calculates the relative time string (“1 hour ago” etc…) based on the last recorded event. This mimics the main screen of WDI. There is a one-to-many field to a history table that holds the individual history items for all actions. This is like the middle tab of WDI. The default style of entering data in a form is a bit tedious compared to WDI: I would have to select an action, select the linked field, hit “+”, tap to set the date, tap to set the date. The thing that makes WDI great is the one-tap quick logging of events like this.

    As a workaround I created a script that adds a linked entry with the current datetime pre-filled, but it also takes several taps to get to scripts so I abused the ability to run scripts via URL to create a “button” on each action record. Basically, this is a URL field where the URL is a TapForms link to run a script with parameters containing the name of the action to log. With one tap I can now easily log that event (almost, I have to navigate to the action details first but this is a huge improvement). See screenshot attached for example.

    Amazingly this works! Though there are a few issues.

    1. When navigating back and forth from the documents screen TapForms keeps trying to run whatever the last script was run when opening the document. I’m guessing the parameters from the URL are held in some state somewhere and persisting after the script is run, but not sure why it would even try running the script in the first place. Quitting and relaunching the app works around this, I suppose I should also try just opening a URL the clears the params as the last step of the script.
    2. The relative date string has to be manually refreshed
    3. I use the “mask field value” option to hide the URL itself but it seems the mask will just replace each character its masking with “.”, which for really long URLs doesn’t look great.
    4. The summary badge on the “history” linked field is truncated on iOS(see screenshot attached)

    I imagine you already have a large backlog but here’s my feature requests for what it’s worth.

    1. A new “button” field type that runs a script for that specific record.
    2. A date format option for relative dates.
    3. Ability for scripts to fetch location.

    TapForms screenshot screenshot

    One thing that WDI does is that every time you log an event it automatically tracks the current location. I wasn’t able to replicate this since scripts don’t seem to be able to fetch location data so #3 would fix that. Right now I have a script that calculates the relative date but having that be a formatting option on dates would be more flexible since it would happen whenever a call is rendered which is useful for relative dates.

    But most of all, #1. This would be the most powerful addition to TapForms. Right now we can run a script on a whole form or on an individual field, but no way to run a script for a single selected record. The idea is: you would select the “button” field type and select which script for it to run, and possibly some input params. The script would run for that record only when the button is tapped. This small change could have a big impact on the type of workflows forms can be used for.

    #41724
    Brendan
    Keymaster

    Hi Dave,

    Thanks for the feedback.

    1. That’s right. To print a custom layout you need to select the record details option.

    2. Yes, that’s right. This is by design. By turning off Multiple Records per Page, you can print the same label over and over again on the page.

    3. This is because when you have a Link to Form field, the parent record is one thing, but there can be many child records, so displaying them as a table of values is an appropriate display format. However, on a child form, you can add a Calculation or Script field that references fields from the parent. This works with the One to Many Link Type.

    4. That’s right. It’s because normally you use the labels layout to printout labels, so you wouldn’t want a header to be printed at the top of your labels sheet. But I know it would be useful to have a header if you were using the labels layout just to organize the printout differently than just for labels.

    5. The Default Layout is dynamically generated, so I can tell the size needed for printing before it’s printed. On a custom layout, you choose the dimensions of every element. But yes, it would be good to have some sort of sliding fields capability. It wouldn’t really work for a custom layout though. At least not in its current design.

    6. Hmm… Sorry about that. You can click on the Layers tab to find all objects in your layout, even if they’re outside the printable area and you can delete them from there.

    There aren’t really any workarounds for the issues you’ve brought up other than using the Calculation or Script field features.

    Thanks,

    Brendan

    #41706
    T.L. Ford
    Participant

    Thanks! The defaultValue documentation version just hasn’t gotten to me yet, but I used it anyway for faster data entry with a couple sometimes-repetitive fields. I really adore Tap Forms and it’s wonderful that you are actively working on it.

    Script field code below is provided for other people who might find it useful. As a record gets added, the default value changes to the current data so it isn’t necessary to enter it on subsequent records unless the value changes (i.e. it’s easy to enter multiple books by the same author purchased in the same year).

    function Change_Default_Values() {
    
    	var author_id = 'fld-d3d7e4d8d3104c70a002ba5016f597c1';
    	var year_id = 'fld-a6fa7f9e718640d0b52c6f3baa5a40db';
    
    	var author_fld = form.getFieldWithId(author_id);
    	var year_fld = form.getFieldWithId(year_id);
    
    	var author = record.getFieldValue(author_id);
    	var year = record.getFieldValue(year_id);
    		
    	if (!author) { author = ""; }
    
    	author_fld.defaultValue = author;
    	year_fld.defaultValue = year;
    	
    	document.saveAllChanges();
    
    }
    
    Change_Default_Values();
Viewing 15 results - 1,696 through 1,710 (of 2,952 total)