Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
August 4, 2021 at 9:38 AM #44910
In 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,
KimberleyJuly 20, 2021 at 3:47 PM #44832In reply to: Linked Checkmarks
Sam Moffatt
ParticipantI did a checkbox flip flop thing a while back using scripting. Looking at that post, field ID’s are now available in the UI for fields so you don’t need to use the form logger to get the script field ID.
It should be easy enough to copy and paste to handle the toggle properly. I did some updates for my toggle that also set a date field when my “confirmed” field is toggled and also reset the state if some other metadata is set that indicates that it should be in “confirmed” state.
July 20, 2021 at 3:45 PM #44831In reply to: Checkbox Flip Flop
Sam Moffatt
ParticipantUpdate to this because I realised posting in another thread the OP here had a bug where
newStatewasn’t reset when toggling the corresponding checkbox. This should fix this and remove the form logger because you can now get the script field ID in the field list.Replace the field ID’s (e.g.
fld-2adb9ba8cdd048bbbb614d46b415ada5) with the field ID’s from your form. The field ID is located under the description box for that field.// Import the logger and output the header. document.getFormNamed('Script Manager').runScriptNamed('Logger'); logger.consoleHeader('Checkbox Flip Flop', 'Shipments'); // Get the current values of the check boxes. var confirmed = record.getFieldValue('fld-2adb9ba8cdd048bbbb614d46b415ada5'); var unverified = record.getFieldValue('fld-abdb319b7db74fc39812a94778c433cc'); // Get the current value for this script field. var oldState = record.getFieldValue('fld-2cd0296ea0884c8cba3640d8e33f010b'); // Create a copy of the new state for later. var newState = {'confirmed': confirmed, 'unverified': unverified}; // For debugging, log the various states. logger.logMessage(`Current State: ${oldState}`); logger.logMessage('New State: ' + JSON.stringify(newState)); // If we have an old state, we parse it out (otherwise it'd be null). if (oldState) { oldState = JSON.parse(oldState); } else { oldState = { 'unverified': false, 'confirmed': false }; } // If the old state was unverified and not confirmed and this is confirmed... if (oldState['unverified'] && !oldState['confirmed'] && confirmed) { // Update the unverified field to not be set. logger.logMessage('Unsetting unverified flag since confirmed flag toggled'); record.setFieldValue('fld-abdb319b7db74fc39812a94778c433cc', false, false); newState['unverified'] = false; } // If the old state was confirmed and not verified and this is now unverified... if (oldState['confirmed'] && !oldState['unverified'] && unverified) { // Update the confirmed field to not be set. logger.logMessage('Unsetting confirmed flag since verified flag toggled'); record.setFieldValue('fld-2adb9ba8cdd048bbbb614d46b415ada5', false, false); newState['confirmed'] = false; } // Save the changes to the database. form.saveAllChanges(); // Turn the newState into a JSON string. var result = JSON.stringify(newState); logger.consoleFooter('Checkbox Flip Flop', 'Shipments'); // Return the JSON string for the next execution run. result;July 20, 2021 at 6:22 AM #44830Topic: Linked Checkmarks
in forum Using Tap Forms 5Anthony Harrison
ParticipantHi
Deep in my heart I know the answer is “Javascript” but does anybody know a way to link say, two checkboxes so if box “YES” is clicked then box “NO” can’t be? It is a visual thing for scrolling through records, I realise that an alternative would be Tick/No Tick but I prefer that a positive action is made.Many thanks if you can help.
July 18, 2021 at 3:13 PM #44827MiB
ParticipantHi Sam,
since today, everything is working just fine. – Thanks to the tremendous help from Brendan.Here is what he has written:
One, your info.txt files should have been UTF8 encoding, but they were MacOS Roman. Tap Forms assumes that it’s fetching UTF8 encoded data, so when it encountered MacOS Roman, the conversion from binary to a string returned a null value. When I changed your info.txt files to be all UTF8 encoding, then it worked.
Two, the URL for the photo was not generated right. You were reading the photo filename from images.txt, but you were using that value as the URL.
If someone has the same problem I have had after knowing this, here is a solution:
I have over 800 info.txt files in over 800 subdirectories which are NOT UTF8 encoded.
To get them converted in one go, use this line:find . -type f -iname “info.txt" -exec sh -c 'iconv -f MACROMAN -t utf-8 "$1" > converted && mv converted "$1"' -- "{}" \;I’ve used
-inamebecause I have info.txt (lowercase “i”) and info.txt (uppercase “i”) files.
“converted” is only temporary to overwrite the existing file. (Otherwise iconv would work like this: info.txt > info1.txt.The complete code and samples are in the zip file. (Already in UTF8)
As mentioned above: You just have to change the username “mib” to your own in the Script and in the command file.Attachments:
You must be logged in to view attached files. -
AuthorSearch Results