I’m importing some records of clients via csv. One column in the csv contains multiple appointment dates per client.
I want the clients to go into my Clients form. The Clients form has a Link to Form field called Appointments. It’s a 1:M field and “Show Inverse Relationship” is checked.
I need the clients to be imported as records in the Clients form, and the multiple dates per client from the csv to be entered as child records in the Appointments form.
I don’t think there’s a way to do that all in import, so I figured I’d:
1. Import the csv into Clients, while creating a new field “Dates to Process” to capture the multiple appointment dates
2. Use a script to loop through “Dates to Process” and create the appropriate records in Appointments
For step 2, I’m pretty sure I can loop through the “Dates to Process”, but I don’t know how to apply each date as a new record in “Appointments” that’s associated with that client in the parent Clients form. I see that in the script editor, I can tap on one-to-many icon next to Appointments, and get its ID, but after that, I’m at a loss.
Any help would be appreciated!
Additionally you can use a “Calculation” field in the “Role Map” form to copy across details from the consultant table. This should get updated automatically when the consultant record is updated though there are a couple of times where I’ve confused TF enough for it not to propagate the changes (the exception not the rule).
Sorry for resurrecting this thread, but I did have a question about the advice above (for my own understanding).
Since the underlying data (the “truth”) is already stored in the related form, why would one copy the data into the calculation field? Is this not redundant as opposed to, say, referring to the original data field using a script?
One possible advantage of doing that (at least that I could identify) would be to transactionally put the related data into a calculation field and then not update the field unless directed to do so by the user. This would have the effect of setting the data at “time zero”, allowing the underlying data (in the related field) to be updated without modifying the related record. In situations where one needs the correct historical record AND the ability for the related forms to have updated information as time goes by, this could be an advantage. However, in my limited knowledge, this is not the way Tap Forms works, correct?
Thanks for any insights.
When you’re working with a linked record, you need to get a copy of that record. If you double click on “Procedures” it should insert some code to help you get the procedure record. It should look something like this (if it inserts just an ID then you can update it to match):
var procedures = record.getFieldValue('fld-1234');
Where the fld-1234 piece will be the value that the script editor puts in when you double click on the “Procedures” section heading. I did a video on building a script that has some details that might be useful. There are a few other videos on the channel that could fill in some gaps. There is also T.L. Ford’s Tap Forms Scripting 101 and 102 as other resources that might help.
That said since you’re on the “one” side of the 1:M field, if all you’re after is copying the value from the parent then using a calculation field is likely going to be simpler. Calculation fields in that situation will let you just double click the field you want and it should do the heavy lifting for you.
One schema recommendation is to use a third form that stores two link fields for going back to patient and procedure. You link 1:M from Patients and Procedures into this new form, let’s call it “Appointments” (I’d use “Operations” but that could be confusing), make sure you tick “show inverse relationship”. This leaves the “Appointments” with a single link back to the other two forms which means you can keep stuff like patient name unique unless you don’t have a lot of recurring patients. If what you’ve got it working that’s great but I’d generally take a step further to split patient from the instances of a procedure they have so that their data (name mostly it seems) is only in one place.
Hello all,
I am trying to migrate an existing FM database to Tap Forms. Before I purchase I am trying to ensure I can make the basics of my existing db work.
Please forgive my naïveté as I am a beginning user of Tap Forms.
I have two tables: Patients and Procedures (surgical).
A patient can have one surgery; many people can have a given surgery. Therefore, on the Procedures table (screenshot 1) I have ‘Patients’ set up as a one:many field. I have the ‘link to form’ turned on so that, in my Patients table (screenshot 2) I can see the linked information correctly.
What I am attempting to do is to get the values of some of the related fields (from the Procedures table) into the Patients table. I am using a Script field for this. As per the attached screenshot, I am first trying to get the ‘OHIP code’ (‘C111A’ in the second screenshot) into its own field on the Patients table.
I have attached a screenshot of my script where I attempt to do so. It is not working and I know the fix is likely something quite simple.
In the Script window, the field ID was obtained by double-clicking on the “Code” field in the “Procedures” table on the left-hand side of the window.
Any help to get me on my way would be much appreciated.
Thank you.
Phil
Attachments:
You must be
logged in to view attached files.
Hi Chris,
That’s a cool use for Tap Forms!
I took astronomy in university. It was one of my favourite courses.
Although you’ve figured out another way to do what you want, your original question could be answered with a script to fetch an image from somewhere and populate the image in your form. If you had a folder on disk with photos in it, you could write a script to add a photo to your field from a URL using record.addPhotoFromUrlToField(url, field_id); You could set the photo field empty before adding a photo to it, otherwise you’d get multiple photos in the field.
Anyway, just thought I’d chime in with this bit.
Thanks!
Brendan
What about something that triggers a Form Script in Tap Forms that uses the new parameters feature that then causes the script to call back to an Amazon API to get the product details? I don’t know anything about building Chrome extensions though.
But there’s information about calling a Tap Forms Script from a URL and passing it parameters here:
https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api
Possibly one way that would be relatively quick, although as Sam said, would get slower over time too, but would be easy to implement, would be a script that simply looped through all the records and re-numbered them all from 0…N, for whatever numbering scheme you are using. You wouldn’t need to look for holes as this would effectively eliminate holes and your new records would just go to the end. But then as Sam suggested, reusing IDs or in this technique, changing IDs of an item isn’t always a good idea. But it really depends on what your workflow is.
I think a script would be a lot of overhead for this just because as the number of records increases, you’d have to scan through them to find where the holes are and allocate a new ID. It’s possibly but it’d get slower over time.
What I think might make more sense is a script you call to empty the record out and then a script field (that you can hide) that detects if some key fields are empty which you then key into a saved search for “available” records. Then you can repurpose those records as you need them.
I personally don’t think I’d ever want to reuse ID’s in a collection and would probably always keep them as is with a flag that says I don’t have the item any more but that’s perhaps just me.
You can do it but it relies upon using CouchDB sync (or Cloudant) to land the items. I use CouchDB as my sync and I have a bunch of Greasemonkey/Tampermonkey scripts that I use to push stuff into Tap Forms.
Basically you can create a document in CouchDB with the same structure as a Tap Forms record. CouchDB let’s you do a POST to it to create a record via it’s web interface, Tap Forms then sees that record as a new record and it pops into it’s UI.
I have two scripts that I use to automatically import this forum into a Tap Forms document as I navigate around it, essentially each time I go to a page on the forum, it scrapes the page into CouchDB and then shows up in Tap Forms. Here’s a copy of the topic collector piece that shows importing topics and authors as new records. It’s a bit of a hack as there are some protections on the tapforms.com side to prevent sending to external domains (hence the cspbypass.google-analytics.com hack).
I started building one to import Amazon product pages but I never finished it. It’s a fair amount of work to basically use Javascript to extract out the pieces of the page you’re interested in and then splice it into a Tap Forms document. Not impossible just time consuming.
Hi Sam,
Thanks for your reply and pointing this out!
Field script does the trick, rounds up from 0,5.
So it works!
I’m anything but a programmer, didn’t know about these rounding rules (Rounding is no a straightforward subject though once you start reading on the subject ;-) But interesting ).
Cheers
Eric
First of all, I know about the auto-increment function of a number field. But it’s not what I am looking for. Why? Because the field continues to count from the last position even if old records are deleted.
This means:
I need a script to fill in the gaps (freed up inventory slots) in the database when records are deleted and after that, created.
I want to use the inventory number as just it, a fixed number for a record (readable) and I don’t want gaps.
Can somebody help me with it? I think it’s understandable that you need something like this for managing collections of items (i am a collector).
Thanks!
Nice start to a generic entry point! I have some suggestions for improvements :)
Instead of this long line:
if (param == 'JLRouteScheme' || param == 'JLRouteURL' || param == 'formID' || param == 'JLRoutePattern' || param == 'docID' || param == 'scriptName')
You could use an array and simplify the if statement and skip to your else directly by using Array.includes:
var ignoredParams = ['JLRouteScheme', 'JLRouteURL', 'formID', 'JLRoutePattern', 'docID', 'scriptName'];
if (!ignoredParams.includes(param)) {
The other thing would be to use a switch statement instead of the if/else:
var theField = form.getFieldNamed(param);
if (theField == undefined) {
console.log(`No field called ${param}`);
continue;
}
switch(theField.fieldType) {
case 'text':
case 'web_site':
record.setFieldValue(theField.getId(), parameters[param]);
break;
case 'photo':
record.addPhotoFromUrlToField(parameters[param], theField.getId());
break;
case 'script':
console.log('Cannot set value for a "script" field type');
break;
default:
console.log(`Unsupported field type ${theField.fieldType}`);
}
I’ve not personally noticed the rounding behaviour but it sounds to me like an implementation of IEEE 754’s rounding rules for round half to even which is a strategy for mitigating rounding bias.
You might be able to use a script field to have Javascript do the rounding for you, I believe it uses the round up strategy.
Am I right in finding that 0.5 is occasionally rounded down instead of up? Is it that rounding decimal places in Javascript can go “quirky”? And can it be solved in TF calculation fields?
What would be the best approach?
Thanks for any advise.
Eric
Hi,
I just made a quick utility to simplify adding records to Tap Forms from other apps.
It actually allows adding of records from any app (e.g. Shortcuts, Drafts) that can call a URL.
To use:
1) Install: Add the attached script as a form script to the form you want to be able to add records to.
2) Run the script in Tap Forms and it will display the URL you need to use in Shortcuts to add a record
3) Create a Shortcut calling that URL with the parameters matching the field names in the form (for the fields you want to set)
I’ve only added support for adding text values, URLs and photos, but there is nothing to stop other field types, such as rating, being added.
Hope someone finds this useful,
Martin
Attachments:
You must be
logged in to view attached files.