Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
August 14, 2021 at 1:00 AM #44967
In reply to: Programatically or automatically import
Brendan
KeymasterAnd with setting the Script Folder on the Preferences screen, you can put your data in there and then use
var data = Utils.getTextFromUrl(url);command to read in the file. Then parse it. Thesplit()function could be used to split the lines into an array of lines. Then for each line, use split again to split by the column delimiter. But it really depends on how your data is structured. If you have delimiters within your content and quoted content, then that would be much more difficult to deal with. I should add a JavaScript API for parsing delimited content into two dimensional arrays of data, basically giving you access to the code I already use for parsing CSV files.August 9, 2021 at 8:49 AM #44938In reply to: Programatically or automatically import
Daniel Leu
ParticipantI don’t see an API for that. In one of my applications, I use the clipboard to import data into TF. It took a bit of time to get the data parsing right, but now it works well.
If your data is already in CSV format, the parsing should be easy. I don’t think that such a script is that difficult since you already know where the data should go. You then call the script with
tapformz://script/[document ID]/[form ID]/[form script name]?key1=value1&key2=value2...Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksAugust 8, 2021 at 4:18 AM #44934Topic: Programatically or automatically import
in forum Script TalkTom Kerswill
ParticipantHi
Is it possible to import data programatically? Ideally by using an existing import preset?
I’d like to have something like Hazel or Keyboard Maestro trigger this when data in a file changes, so that I can reimport it into Tap Forms.
I suspect I could probably do a form script that might do this; but ideally it would be able to trigger Tap Forms’ existing import system, as it can then do things like automatically setting links to other forms, etc., whereas I suspect this would be quite complex to do if building an import script from scratch.
Thanks in advance,
Tom
August 4, 2021 at 4:15 PM #44915In reply to: How to import “linked” forms
Sam Moffatt
ParticipantYou can use a script to get the children of one Link to Form field of JOIN type and then add them to another Link to Form field. In terms of script, a form script like this should do the trick:
record.getFieldValue('fld-joinfieldid').forEach(rec => record.addRecordToField(rec, 'fld-1tomanyfieldid'));You could expand it to run on all of the records in your form but this will do just the currently selected record. I haven’t tested it but it should work.
August 4, 2021 at 9:38 AM #44910In reply to: How to import “linked” forms
Aaron Greenhouse
ParticipantWith regards to the import problem, I was importing into a new empty document.
The problem I have with the Join Link type is that I created a new database for purchases and items after date X, and in that database I have used the 1 to many link type and set the links explicitly. I would like to import my old data from the spreadsheet (from before date X) into the new database. I cannot have both JOIN and 1-to-Many for the same field. I suppose I could have two fields, “Purchase” and “Legacy Purchase.” I could live with that. Is there a way, perhaps using a script, to copy the references from a “JOIN link” field to a 1-to-Many field?
August 2, 2021 at 9:38 PM #44902In reply to: Decimal Formatting in Calculation Field
Sam Moffatt
ParticipantThe other two numbers round correctly to the right value:
0.5600000000000001 0.560000000000000053290705182007513940334320068359375 0.5500000000000000444089209850062616169452667236328125 0.56999999999999995115018691649311222136020660400390625The script field is probably the answer if you really want to fix it, I don’t think there is a way within a calc field you can make it work when embedded in a string like that.
August 1, 2021 at 12:56 AM #44882In reply to: Decimal Formatting in Calculation Field
Sam Moffatt
ParticipantWhat is the type of current year rate? I was trying to figure out how to repro this to figure out a viable solution but I didn’t see one. I create a number field and populated it with 0.56 and the text calculation field printed .56 as the rate as I’d expect. I tried doing it as a calculation field with
56/100but that didn’t seem to trigger the weird behaviour either.What you’re seeing is floating point rounding errors. The 0.56 ends up being stored as 0.560000000000000053290705182007513940334320068359375 which is why you see 0.5600000000000001 as the 5 rounds up:
0.5600000000000001 0.560000000000000053290705182007513940334320068359375I suspect this is a reflection of the underlying JSON data model (Javascript floating point numbers are IEEE-754 64-bit double precision numbers) and unfortunately leaking out. For some more gory details I found a YouTube video on floating point representation and rounding error and an online converter that lets you put in 0.56 and see what the computer is doing.
I have an sprintf implementation that I ported for printing formatted strings in Javascript that should handle it if you want, there was a not dissimilar thread on if to use a calc or script field that shows formatting floating point numbers. That may yet be the solution for you as well but it’s a bit heavier than a simple calc field.
July 28, 2021 at 1:31 AM #44873In reply to: Link to dates in form
Brendan
KeymasterI wonder if a Table field would be ideal for this sort of thing?
Do you mean that if you change a date on the Parent record, all the linked records would have their dates updated? So if the parent field had a Project Start Date and the Table field had a Task Start Date, if you change the Project Start Date to something later, the Task Start Date for each task would also change?
If so, then a Script field would certainly be able to do this. Just loop through all the Table field records and update the Task Start Date depending on the Project Start Date.
I don’t know if it would be all that difficult. And doesn’t use a Linked form, although a Table field is similar to a Link to Form field in the way it displays. It just doesn’t have a separate form for it. The sub-fields are all configured on the Table field itself.
But maybe I’m misunderstanding the requirement.
Thanks,
Brendan
July 27, 2021 at 10:21 PM #44870In reply to: Link to dates in form
Sam Moffatt
ParticipantI don’t think there is an easy way to do this, or even a hard way for that matter.
The feature you’d need is self linking forms and whilst it sort of works, it only does so for M:M links when for this you’re building a tree like structure that would be 1:M. I got something sort of working with two link to form fields but it was janky and didn’t quite work the way I’d like and would still put the parent record in the child section. That would mean a second form to store the links and likely a bunch of scripting to replicate the TF record picker. Not impossible and with a lot of work, you could build the linking infrastructure you’d need to make it work and then once you’ve got that a moderately complex script field could push the update.
July 27, 2021 at 4:17 PM #44868In reply to: what is wrong
Sam Moffatt
ParticipantAs a script it’d be something like this:
function Flag() { var classtype = record.getFieldValue("fld-fieldid1"); var yps = record.getFieldValue("fld-fieldid2"); return (classtype == "Std" && yps > 3.64) ? "" : "?"; } return Flag();Note:
classis a reserved word in Javascript so not a valid variable name.The
fld-fieldid1is the ID of the field, the script editor can help you generate a line for that (double click field on desktop or on mobile there is a field picker) with the variable name and field ID preset. You can also get the field ID from the form editor when you select the field to splice in the ID yourself.You don’t need the full function wrapper but I find it feels more natural to do the return statement. The return is using a ternary operator to do the comparison compactly.
July 27, 2021 at 7:25 AM #44866In reply to: what is wrong
Tim Flick
ParticipantWhat this same calculated field look like in a script Thanks much
July 26, 2021 at 7:28 PM #44864In reply to: Display GrappObject
Sam Moffatt
ParticipantScript field is Javascript so anything you can code into Javascript you can put as a condition. It’s a bit more verbose than the calculation fields but I feel a lot more flexible and expressive plus the development loop is a little easier as you can run it inside the editor and see the result (or get an error on the console from the JS interpreter).
For each field, you need to do a
record.getFieldValueto grab the value and then you can do what ever operation you need (obviously limited by Javascript).July 25, 2021 at 9:56 AM #44852In reply to: Display GrappObject
Sam Moffatt
ParticipantOn the emoji front, I went looking for something that could automatically take the country and turn it into a flag, I found some sample code that used the country code to turn into the flag. I pulled that into a script and it seemed to work out ok:
function getFlagEmoji(countryCode) { return countryCode.toUpperCase().replace(/./g, char => String.fromCodePoint(127397 + char.charCodeAt()) ); } function Flag() { var country = record.getFieldValue('fld-7769fdcb2a4f46a8a225db562a289359'); return getFlagEmoji(country); } Flag();Replace the field ID with your field ID, if you want to do some extra translations or mappings then you can do that in script but if you do some data wrangling this won’t be too bad. I grabbed the country code list from W3Schools and pasted it into a new form with the above script via the MCLV and it’s attached below as a Tap Forms Archive.
Attachments:
You must be logged in to view attached files.July 24, 2021 at 1:13 PM #44848In reply to: Display GrappObject
Brendan
KeymasterHi Tim,
You could maybe do something like that in a Script, but use Emoji’s for the flag instead of a graphic object. Although I guess depending on what you’re trying to do, just a Calculation field that looks at a value from a field and returns an Emoji flag character depending on the result.
Something like:
IFEQUAL(Country; "Canada"; "??"; "")So this says, if the value of the Country field is “Canada”, return the Canadian Flag emoji, otherwise, return nothing.
Thanks,
Brendan
July 22, 2021 at 5:22 AM #44841In reply to: Existing Forms need Relationship Editing
Kimberley Hoffman
ParticipantI am going to pick up where I left off. Book number four is at the printers and I am thinking of how to organise the fifth one using Tap Forms. Book number three has been long-listed for the world illustration awards. :)
Since the file I use for keeping track of my participants works – it is a separate file not connected to any client based files – I was wondering if there were any way to link to the client based file?
I’ve been giving this some thought. I only need a project file as long as the project is active. After that I prefer to retire it out of view.
Things that I need for my project file from the client based file would be client, client contact details, client number.
I would also need to add contact details of people that are involved with the project, but who are not the client. This could include city marketing companies or tourism associations, for example.
Would it make more sense to just create a field to link other files, separate from the project, as you would with documents or structure it so that the all the files are linked?
One note here: The participant files are always completely separate documents from the client files.
I need some room to think out loud now and hopefully get some logical feedback, whilst my mind springs from tree to tree
Ideally for the project file I would have three forms:
1. The project detail form-
Project name
Project number (which is dependent on the client’s number – which is why I really would like to connect it to the client & acquisition file or visa-versa)
Work hours and details imported from a csv-file (I use Tyme2, which has proven to be very good for me)
Time planning, like as in a Gant-Chart (page 1 needs to be done by this date, page 2 by then, etc)
Project description
Information about repetive characters including a brief description and linked turn-around drawings
An additional contact list of people involved in the projectClient information
Support information (people who are important to talk to, places to draw about)2. The participant form
This form contains cvs-data imported from my newsletter provider
I might need to add the details (names, ages, addresses if different from the person who organised the participation) to the form. these aren’t contained in the original registration. Germany is very strict about data collection. This would have to be manually added.
I also use this form to provide the press with statistics. Therefore, I do not wish to create separate entries for people in the groups and family type categories. That would skew everything. This time around I duplicated the entry, changed the number of participants to “0” and put in the address of the person/people pre-ordering books.I use the filter to filter out the number of books pre-ordered so that I can send that information to the publisher to process.3. Book pre-orders
This should populate from the participant form, however as I just experienced this week, people who are in groups pre-order for themselves and aren’t listed personally in the participant form. I can only find them by searching the email registration and the documents submitted. Their addresses are not listed and the books would be billed and delivered to the wrong address otherwise.Does anyone see any holes in this? I would appreciate any feedback before I set up the next file. Thanks
Regards,
Kimberley -
AuthorSearch Results