Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
July 17, 2020 at 3:19 AM #41335
Topic: Notes field – how to test if empty
in forum Script TalkVictor Warner
ParticipantI would like to combine a Notes field with other in a script, but if the Notes field is empty I wish to display just the other fields.
I have created a test database with a test script as follows:
var notes_id = 'fld-9d8543d9d39f409194349c1a855d7728'; var notes = record.getFieldValue('fld-9d8543d9d39f409194349c1a855d7728'); var new_work_address_id = 'fld-943ab25fd0de42e7b8d1e5487c6a358b'; var new_work_address = record.getFieldValue('fld-943ab25fd0de42e7b8d1e5487c6a358b'); if (notes == "") { result = new_work_address } else { result = new_work_address + "\n\n" + notes; } resultBut if the Notes field is empty the result is the content of new_work_address plus plus the word ‘undefined’
Is there a way to test for whether a Notes field is empty?
July 17, 2020 at 1:40 AM #41334In reply to: A Few Questions
Sam Moffatt
Participant2. I’ve thought for a while that a custom layout using the default layout view but with the ability to re-order fields and hide ones that aren’t important would be an interesting addition and could provide a form of custom layout support on the mobile platforms as well. I used section headings to collapse down records and keep them clean during editing though that isn’t a good fit for your use case.
3. The problem is that those fields are still editable in the sense that they can create an entry on the other side of the link. I can see your use case though and I think an implementation path forward could be per record overrides for field settings which could hide the field just for that record via a script interaction (though that isn’t a feature that exists today).
5. TF uses Apple’s JavaScriptCore for the scripting so almost anything you can do in JavaScript you can do in Tap Forms. Check out the JavaScript API for details about Tap Forms specific functionality but you can manipulate almost any data item in the application via the scripting interface.
As an aside, editing the post generally gets caught by the antispam as that is a technique to change a post after it’s been visible to hide links in it. I’ve been caught a few times by it myself.
July 17, 2020 at 12:17 AM #41331In reply to: Tap Forms for Magazines
Sam Moffatt
ParticipantThat’s a limitation of that particular model because you can only link to a form record not an entry inside a table field. It looks like what you’re after is more the article than the magazine so if we pivot a little to make the ‘Articles’ their own form then you can skip the script and just use a Link to Field with JOIN and I think it’ll give you the read out you’re looking for.
Here is a new TFArc with a new
Articlesform setup as a Link to Form JOIN to theKeywordsform and also setup with a Link to Form 1:M fromMagazineto map that back. Inside ofArticlesI added two calculation fields to map down fields from theMagazineform into theArticlesone which can be seen in the list view inKeywords. The existing fields are still there but with some renames.Attachments:
You must be logged in to view attached files.July 16, 2020 at 10:17 PM #41329In reply to: Question about Search Filters
Brendan
KeymasterHi Rocky,
That’s interesting. I would have thought that if the record didn’t quality for the search results after the script is run, that’s why it would disappear. But you said that the script does not touch a field that’s in the list of search rules.
Would you be able to email me your form template so I can test it out here?
Thanks,
Brendan
July 16, 2020 at 8:53 PM #41326Topic: Question about Search Filters
in forum Using Tap Forms 5Rocky Machado
ParticipantHi Brenden – Not sure if this is by design, but thought I would ask. I currently have a Trade Journal form layout that has a button which executes a script. I noticed that when I’m in a search filter and execute the script via the button click. I noticed the transaction disappears from my search filter list and I have to hit the refresh (recalc the search filter) button in order for my transaction to show up on my list again. The filter criteria for my search is based on a date/time field (looking at today transactions). The fields that I’m populating has nothing to do with the search filter so I am not quite sure why the transaction would disappear (unless it event driven). Is this the expected behavior? So to make this work, I have to click the button and then hit the recalc button for the record to reappear. I’m wording if I am doing something wrong. When I execute the script I do a form.saveallchange() for my changes to take effect.
thanks,
rockyJuly 16, 2020 at 12:25 PM #41316In reply to: A Few Questions
Christin White
ParticipantHuh, okay, every time I try to edit my post it deletes it instead, sorry for the multiple pings, hopefully I’ve figured out the way to get the markdown to not collapse spaces and dashes, if not apologies for not being as clear as I’d like.
—
Thanks Sam and Brendan!
1. Brendan’s suggestion worked for me, If I have trouble in the future I may look at those other sync services.
2. Hmm, that does make sense in this context and having a single form for media that can match some pre-selected types is a more elegant way to approach this, it just means each record will have a lot of superfluous fields specific to other types of media.
I hadn’t played with custom layouts yet, having done so now I feel like it’s a bit clunky and page/print-centric for me, I definitely prefer the more responsive UI design of the default layout, it’s a pity that it can’t be duplicated but some fields simply hidden or even just section headings collapsed for each layout.
3. That’s certainly a good idea but this was just an example, combining media types or people and companies into combined forms aren’t always going to work for every example, it would be nice if records could be toggled to simple hide unused inversely linked fields.
4. Along the same lines it would be sweet if *Many to Many* relationships with only a single link could collapse to a non-table view or a *Many to One* option existed.
5. I did a poor job articulating this but it looks like you got the idea. Basically, I want a tagging system tags can be nested and parent tabs inherent the items of their child tags like Bear does. So basically you get something like this:
Parent Tag 1 (Record 1, Record 2, Record 3)
Child Tag 1 (Record 1, Record 2)
Child Tag 2 (Record 3)Bear does this by simple parsing tag names for slashes and extracting the tag structure from that but I’ve seen other apps implement it in other ways. Keep It does something that’s similar and creates some sort of implicit hierarchy from a flat list of tags. When you select a tag to filter by the tag panel then filters out any tags that aren’t designated in other items with the tag selected so you very quickly create structure through boolean unions.
Regardless, assuming Tap Forms’ scripting is capable of parsing regex expressions, assigning and removing tags programmatically I think the functionality I’m looking for could be implemented that way. I’ll definitely take a look at that example and think through your suggestion further, I think I’m still missing a little contextual experience with the application to entirely understand but it sounds like it’s worth a try. Thank you!
—
Tap Forms seems like an awesome system, while not quite as flexible as I would like for some things, I certainly realize I may be an outlier on how I want to use it. With some care in how I design things and a certain amount of clutter I think its worth the investment and will work for me.
My goal was to move away from AirTable to something more native to the platforms I use every day and to escape the limits by subscription tiers and Tap Forms achieves both goals and does so quite well overall.
July 16, 2020 at 11:48 AM #41312In reply to: A Few Questions
Christin White
ParticipantThanks Sam and Brendan!
Sam,
1. Brendan’s solution seems to have resolved the issue for now, if I have more trouble with things in the future I may look into those other services.
2. Hmm, I hadn’t considered this approach but having one form for all media seems like a more elegant solution than a bunch of forms, even if it means I have a ton irrelevant metadata for each record, I’m liking this better! I’m not much of a fan of custom layouts though, I hadn’t realized those were an option before you mentioned them but playing with it now it seems very paper/page-centric in design, not really UI-centric and responsive to different device screen sizes. I wish I could just take the default layout but just hide fields for each layout. I may play with this more but it seems to lack the elegance of the default layout. I’m definitely spoiled coming from AirTable in terms of design elegance, I just wanted something native and not limited by subscription pricing tiers.
3. Good point, certainly, but that was just an example, combining things like media types or companies and individuals may not always make sense. I can work around this but it’s a shame there isn’t more control.
4. I get that but it’s a pity it doesn’t collapse the table if there’s only a single relationship or a many to one option.
5. I’ll take a look at your scripting, I was having trouble describing the system in a clear way. Basically, I want a tagging system sort of like thisParent Tag 1 (record 1, record 2, record 3 - collected/reverse inherited from children) Child Tag 1 (record 1, record 2) Child Tag 2 (record 3)Bear parses tags by just using slashes in the tag names like
Development/Languages/Javascriptbut that’s only one approach. Keep It for instance doesn’t do hierarchical tags but if you filter by a tag the tag panel will then show you other tags that associated with items that has that tag so hierarchy can be implied through boolean unions.A programmatic solution where any record that is assigned
Child Tag 1would automatically tag it withParent Tag 1would certainly work if Tap Forms’ scripting support is robust enough parses regex expressions, assign and remove tags, it sounds like it is.I need to explore a little more, look at that keyword mapping and figure out what you’re suggesting a bit better when I have more context.
—
While not as flexible in some ways as I would like it seems like Tap Forms will work for me and is worth the investment, it is an awesome system and I realize I’m probably an outlier for some of the ways I want to use it
July 16, 2020 at 2:03 AM #41306In reply to: Tap Forms for Magazines
pierrot_rennes
ParticipantHi Sam,
I put only one keyword per article to keep it simple
If I really need a second keyword for the same item, I create a second record
Apparently, your script works according to my need.
I will test by adding some articles.
If it’s ok, I will start from your model to modify your form and adapt it to my needs
A big thank you for your responsiveness, I will tell you when it’s goodJuly 16, 2020 at 12:12 AM #41302In reply to: A Few Questions
Sam Moffatt
ParticipantHi Christin,
Responding as a regular user, some of these will require Brendan’s input.
1. I suggest looking at CouchDB or Cloudant as the sync system, I’ve found CouchDB to be reliable and if you’ve only got a small amount of data the IBM Cloudant free tier I think gives you 1GB of space to use (CouchDB is an open source server and Cloudant is IBM’s hosted version of it).
2. I’d probably leave all of those fields in a single form with a “type” field and then use custom layouts to control which quote you saw. It won’t work so well on the table view but a workaround would be to use either a calculation field or a script field to compose the text relevant to the record type, perhaps like a bibliography line generator. You click add, in the ‘quotations’ form select the right layout for th type, put in the data and then you can go back to the parent form.
3. Companies are people too, at least in the US anyway. I’d actually take inspiration from Apple’s approach where if a contact card is a company is a tick box for the contact card and everything else more or less remains the same. You can still filter and search on if something is a company or not and if you bump it up your field list after name, you can have it render in the list view as well (I’d also tick “show field name” on the checkbox as well). I don’t think you can hide the UI if there is nothing there.
4. Many to Many implies both sides could have multiple entries though, that’s why it’s displaying the table because there is the possibility that multiple records will be available or another one could be added even if there is currently only a single record.
5. I’m not sure I fully understand so my apologies if I’m off base but what might work for you is something not dissimilar to what I just threw together for Pierrot for his keywords mapping for magazines. Some amount of scripting could help automate building the linking structure you’re interested in achieving though I must admit I’m not sure I fully understand it. There are a couple of ways of structuring the forms to use calculation or script fields to create surrogate field values (e.g. take the name of the current level such as
Habitsand then prepend a field with the name of it’s parents) which if set to be the first field shows up in the flat list but can maintain the parent association via a 1:M link. Then I’d probably use a normal Link to Form M:M field to map the children of each of the category records to it’s categories that is maintained by a script. You could brute force like the above script or a field script might also work to detect links being manipulated and to automatically propagate adding/removing the links internally.Hopefully that makes sense, I’m sure others on the forums might have different takes and Brendan often chimes in with features that are built in that might handle some of it. I think with some scripting support you can get a little bit further.
July 15, 2020 at 11:37 PM #41299In reply to: Tap Forms for Magazines
Sam Moffatt
ParticipantIf you only had one keyword, then I think a JOIN link to field type would work for you because you could have a single “keyword” record and then it’d automatically JOIN on other records. If you made “articles” it’s own form and used “Link to Form” fields to join it all together then that would work. You’ve gone with a table approach which can’t be used to handle the JOIN.
If you wanted to keep the table, what could work is to leverage a script to maintain the links. I did a really quick one here;
function Build_Keyword_Map() { // This is the other form that has our keywords in it. let keywordForm = document.getFormNamed('Keywords'); // This is the field ID in the "keywords" form for the link to field to Magazines. let magazines_id = 'fld-b4724a28d4094b3faa9910f18374588f'; // This is the field ID in the "keywords" form for the keyword field. let keywords_keyword_id = 'fld-ebaf7ffa3d484834bdcc34d3ffb9c5f2'; // This is the field ID in the "magazine" form of the table. let articles_id = 'fld-dca513dfa3894e8aaa3792a9eb09b106'; // This is the field ID in the "magazine" form for the keyword field in the articles table. let keyword_id = 'fld-055da0f29f764ea399e6f317427ff8ed'; // This is to store a map of keyword to keyword record. let kwRecords = {}; // Build the map of keyword to keyword record (cache if you will). for (let keywordRecord of keywordForm.getRecords()) { kwRecords[keywordRecord.getFieldValue(keywords_keyword_id)] = keywordRecord; } // Iterate over every record in this form... for (let sourceRecord of form.getRecords()) { // And iterate over each row in the articles table... for (let article of sourceRecord.getFieldValue(articles_id)) { // Get the value of the keyword field... let keyword = article.getFieldValue(keyword_id); // Skip it if it is empty... if (!keyword) { continue; } // Check if a keyword record exists for it... if (!kwRecords[keyword]) { // Create keyword record if it doesn't exist... console.log('Creating keyword record'); kwRecords[keyword] = keywordForm.addNewRecord(); kwRecords[keyword].setFieldValue(keywords_keyword_id, keyword); } // Link the keyword record to this record. kwRecords[keyword].addRecordToField(sourceRecord, magazines_id); // Save the changes to make sure the link persists properly... form.saveAllChanges(); // Log the keyword we processed, we're done! console.log(keyword); } } } Build_Keyword_Map();There are comments throughout which should explain what it does and I’ve attached a sample archive with the script in it inside the “Magazine” form. You can play with it to get it to add links. What it doesn’t do right now is handle if you delete or remove a keyword. You’d also have to do a split or similar to do a comma separated list of keywords as well but this is a quick example of how you can use scripting to build that link.
If you change from a table to a child form then you could link a single keyword easily. If you wanted to do multiple keywords (e.g.
Big Sur, Photos) then you’d be back needing a script again.Hopefully this helps :)
Attachments:
You must be logged in to view attached files.July 14, 2020 at 6:51 AM #41279Topic: Script for Printing
in forum Script TalkRoy Helsing
ParticipantI am new to TAP, and made a simple relational database for a lost of music I can play, attached to the genres that relate to that music. I want to be able to print a report for my customers that lists each genre and under it, all song titles that are related tot hat genre. It appears the thinly way to do that iw with a script – which I read about at length yesterday only to decide Java Script is not in my wheel house. Does anyone have a simple script they use to list related items under a field that could share? I think i am able to figure out how to replace the fields in someone script with my one. I am looking for a report that reads like this:
GENRE 1
Song 1
Song 15
Song 432
Genre 2
Song 15
Sonf 321
Genre 3
Song 1
Song 12July 11, 2020 at 4:58 PM #41263In reply to: how to link fields when typing
Sam Moffatt
ParticipantYou can use any of the scripts I wrote with pick lists. You just need to define the two pick lists in the Tap Forms preferences for your document and assign each of the text fields to the correct pick list. Make sure you use a single value select list type (e.g. single value popover, combobox, popup button or radio) because the multivalue varieties would mess up the mapping.
July 11, 2020 at 12:54 AM #41257In reply to: how to link fields when typing
Brendan
KeymasterOops. Actually you’re right. Because the script doesn’t get executed until you select from the first pick list. Darn.
July 10, 2020 at 12:28 PM #41249In reply to: how to link fields when typing
Brendan
KeymasterI know it’s not the same as what you’re doing, but I did once write a script that switched pick lists depending on the value selected from another Pick List. This script switches between a Canadian Provinces and US Sates Pick List depending on the value of the country selected.
function Province_Pick_List_Switcher() { var country_id = 'fld-de7985c881804154b037c68dc4c24414'; var country = record.getFieldValue(country_id); var canadian_provinces_pick_list = document.getPickListNamed('Canadian Provinces'); var us_states_pick_list = document.getPickListNamed('US States'); var province_id = 'fld-b1458c16690744129ff145f7b9607c99'; var province = form.getFieldWithId(province_id); if (country == 'Canada') { province.pickList = canadian_provinces_pick_list; } else if (country == 'United States') { province.pickList = us_states_pick_list; } else { province.pickList = null; } } Province_Pick_List_Switcher();It worked well, but only with the Single and Multi-Valued Pick Lists. Because those fetch their Pick List values when you display the popover as opposed to the Checkbox, Radio Button, Combo Box, etc., which pre-load all the values to display.
July 10, 2020 at 12:29 AM #41244In reply to: how to link fields when typing
Sam Moffatt
ParticipantI re-read this and thought I might be overthinking things, if you want a simple 1:1 mapping something like this might work for you. Create a script field and then use a switch statement to pick the right value.
Here’s an example of autocompleting a country based on a “state” field. I use a switch because I think it’s pretty readable though you could construct an array as well:
function Autocomplete_Country() { var issuing_state = record.getFieldValue('fld-34f6d74d34354f63889f63a705b7d15f'); var country = ''; switch (issuing_state) { case 'Washington': case 'Oregon': case 'Texas': case 'Nevada': case 'Arizona': case 'Florida': case 'New York': case 'California': country = 'United States of America'; break; case 'New South Wales': case 'Victoria': case 'South Australia': case 'Tasmania': case 'Western Australia': case 'Northern Territory': case 'Australian Capital Territory': case 'Queensland': country = 'Australia'; break; case 'British Columbia': case 'Alberta': country = 'Canada'; break; } return country; } Autocomplete_Country();Basically in the
caselines you put each of the values you want to match and then set a variable (in my casecountry) to be the value you want. You can then return it and it’ll display.Here’s the same thing implemented as a map/dictionary:
function Autocomplete_Country_Map() { var issuing_state = record.getFieldValue('fld-34f6d74d34354f63889f63a705b7d15f'); var state_map = { 'Washington': 'United States of America', 'Oregon': 'United States of America', 'Texas': 'United States of America', 'Nevada': 'United States of America', 'Arizona': 'United States of America', 'Florida': 'United States of America', 'New York': 'United States of America', 'California': 'United States of America', 'New South Wales': 'Australia', 'Victoria': 'Australia', 'South Australia': 'Australia', 'Tasmania': 'Australia', 'Western Australia': 'Australia', 'Northern Territory': 'Australia', 'Australian Capital Territory': 'Australia', 'Queensland': 'Australia', 'British Columbia': 'Canada', 'Alberta': 'Canada' } return state_map[issuing_state]; } Autocomplete_Country_Map();It’s a little more concise though you’re writing down the country name each time so possible to get it wrong.
If you’re not after a direct 1:1 mapping of values between two fields, then we can continue down the earlier pathway. If you’re only after 1:1 this would work for you.
One last piece is if you want to make the field editable but still autocompleted, this script will handle that for you. In this case there are three fields: state, country and the script field. State and country are text fields whilst the script field is what we use to retain some state and set values. The script below handles this and includes a reference to itself to allow manual overrides to be preserved when autocomplete would overwrite:
function Autocomplete_Country() { var issuing_state = record.getFieldValue('fld-34f6d74d34354f63889f63a705b7d15f'); var issuing_country_id = 'fld-108b77c0b088457d90671dd71edf3247'; var issuing_country = record.getFieldValue(issuing_country_id); var autocomplete_country_id = 'fld-cf8a4c138a3a437991182f17000580d6'; var previous_country = record.getFieldValue(autocomplete_country_id); if (issuing_country && issuing_country != previous_country) { return previous_country; } var country = ''; switch (issuing_state) { case 'Washington': case 'Oregon': case 'California': country = 'United States of America'; break; case 'New South Wales': case 'Victoria': case 'Queensland': country = 'Australia'; break; case 'British Columbia': case 'Alberta': country = 'Canada'; break; } record.setFieldValue(issuing_country_id, country); form.saveAllChanges(); return country; } Autocomplete_Country(); -
AuthorSearch Results