Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
April 10, 2021 at 2:52 PM #44120
Sam Moffatt
ParticipantDon’t know why it works if you comment out the variables it works. Again I copied and pasted from the website and it worked fine for me so certainly weird. Though I generally try to put the variables at the top of the script personally, a force of habit from QBASIC many moons ago.
Also odd that you get a crash with the async await there, hopefully Brendan gets the stack dump and can see what went wrong there. I’m paranoid about saving things (too many bad experiences with Word 95) so I frequently save things though on the mobile devices it’s a little harder.
April 10, 2021 at 12:44 PM #44119johnny_law
ParticipantThe reason I was playing around with the original prompter code is while using the async function prompter example that Daniel gave me which worked, as soon as I made a setFieldValue(x,y) in the call back funtion Tap Forms would crash. It would not if the script was run in the editor. Only if run directly.
I was thinking it might have to do with the async nature of the call and the field level scripts. But I created a new Field that had no reference in field level scripts and tried to save to that field and again Tap Forms would crash if the script was directly run. On start up the field was not saved. But again if run from the editor it would save the info into the new field. Very Strange behavior.
April 10, 2021 at 9:05 AM #44114In reply to: Scripts and searching
Victor Warner
ParticipantSam,
Thank you for the explanation.
There are a number downstream issues with linking records through a Join.
Attached is an extract from the database with a couple of records to illustrate (Smith, a 1:M link; Kramer, a Join link)
Up to now all Forms were linked by Link to Form 1:M
So adding relevant fields and setting up Link to Form Join is fine. For records added so that there is a common field all join fine.
But some of the other fields which create totals or reference fields for other Forms no longer work. For example:
For the Form Notarial Act
**Client Name 2 field
1. the field Client Name 2 is a calculation field which picks up a calculation field from the Client contacts details Form (which determines if there is a company and if there is use that otherwise uses the last name of an individual ).
2. If the record in is linked by a 1:M link the Client Name 2 field is automatically filled in.
3. But if the record is linked by a Join link it is left emptyIs the answer a script field such as:
// ID of Form 'Client contact details' var client_contact_details_id = 'fld-c53e48e48e3a40c7a5656ab92f39ecc9'; result = ''; // client_name_record = record.getFieldValue(client_contact_details_id); var client_name_2_id = 'fld-0d5ab10b7374418bac721d6446c81b73'; var last_name = client_name_record.getFieldValue(client_name_2_id); result = last_name; result;Number of documents
1. this is a calculation field it counts a field (Type of document) in the in the linked 1:M Notarised documents Form.
2. Bt if the record is linked by a Join link it is left empty.Is the answer a script field? But I do not know that right JavaScript commands to create a total.
There are several other fields which do counts or sums, which will need new fields or be changed to scripts too in this Form.
Any help would be gratefully received.
Attachments:
You must be logged in to view attached files.April 9, 2021 at 10:17 PM #44108Sam Moffatt
ParticipantI also just gave the sample off API page a spin on my phone and it printed out to the console the input as expected. I’m curious if you can take a screenshot of the console in the script editor on your phone after you’ve filled in a few things just to see what it looks like?
April 9, 2021 at 10:08 PM #44107In reply to: Keep field the same value from previous
Brendan
KeymasterIn my mileage tracker sample document, the user selects a record, then runs a script. It copies the old odometer reading from the selected record, then creates a new record and copies the value into the new record as the previous value. Then you can type in a new value and Tap Forms will compute the difference.
So that’s another way to copy values from a previous record. The previous record is the one you’ve selected. The script creates a new record using data from that “previous record”.
April 9, 2021 at 9:19 PM #44105johnny_law
ParticipantI was using a Form script also and could not get anything but ‘undefined’. But Daniels async function call works great.
Very odd. It would be more simple if the original code worked.
April 9, 2021 at 8:43 PM #44102Sam Moffatt
ParticipantI tried your original sample code myself on an iPad and iPhone which worked properly on both. I’m curious why it wasn’t working for you because it worked for me as is in a form script.
April 9, 2021 at 1:04 PM #44096In reply to: Keep field the same value from previous
T.L. Ford
ParticipantI did this using a Field of Type Script on my table and then updating the Default Values for fields, which acted equivalent to a MS Access AfterUpdate event.
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();April 9, 2021 at 6:50 AM #44093cf
ParticipantWhile you are poking around in that code, I also ran into a crash when adding a linked record using the plus-arrow button (the one that adds a record and navigates to it). Unfortunately I am unable to create steps to reproduce since it only happens for some records/forms and not others. In the cases where the crash does occur it happens consistently.
Linked below is the stack trace:
https://gist.github.com/cfilipov/0a6559c7b010ac651c2dfe27cc67a6b2
The relevant part:
Application Specific Information: Crashing on exception: *** -[__NSArrayM objectAtIndexedSubscript:]: index 3 beyond bounds [0 .. 2] Application Specific Backtrace 1: 0 CoreFoundation 0x00007fff204cc6af __exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007fff202043c9 objc_exception_throw + 48 2 CoreFoundation 0x00007fff20580a9a -[__NSCFString characterAtIndex:].cold.1 + 0 3 CoreFoundation 0x00007fff2043fe41 -[__NSArrayM objectAtIndexedSubscript:] + 169 4 Tap Forms Mac 5 0x000000010711c14e Tap Forms Mac 5 + 1675598 5 AppKit 0x00007fff22e87412 -[_NSCollectionViewDataSourceAdapter collectionView:itemForRepresentedObjectAtIndexPath:] + 435 6 UIFoundation 0x00007fff239e4823 -[_NSCollectionViewCore _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 100 7 UIFoundation 0x00007fff239e47b9 -[_NSCollectionViewCore _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 31 8 UIFoundation 0x00007fff239cc726 -[_NSCollectionViewCore _updateVisibleCellsNow:] + 4435 9 UIFoundation 0x00007fff239cdb5a -[_NSCollectionViewCore _updateVisibleCellsNow:] + 9607 10 UIFoundation 0x00007fff239c0a41 -[_NSCollectionViewCore _layoutItems] + 285 11 UIFoundation 0x00007fff23aa0829 -[_NSCollectionViewCore _itemAtIndexPath:includePrefetchedCells:] + 230 12 UIFoundation 0x00007fff23a9a5ac __76-[_NSCollectionViewCore _deselectItemsAtIndexPaths:animated:notifyDelegate:]_block_invoke + 37 13 CoreFoundation 0x00007fff2048199c __NSSET_IS_CALLING_OUT_TO_A_BLOCK__ + 7 14 CoreFoundation 0x00007fff204c40fc -[__NSSingleObjectSetI enumerateObjectsWithOptions:usingBlock:] + 111 15 UIFoundation 0x00007fff23a9a525 -[_NSCollectionViewCore _deselectItemsAtIndexPaths:animated:notifyDelegate:] + 382 16 AppKit 0x00007fff235f9433 -[NSCollectionView _deselectItemsAtIndexPaths:notifyDelegate:] + 144 17 Tap Forms Mac 5 0x000000010705d805 Tap Forms Mac 5 + 894981 18 Tap Forms Mac 5 0x000000010705bf21 Tap Forms Mac 5 + 888609I had three linked records and used the arrow-plus button to add a fourth.
April 8, 2021 at 11:50 PM #44090Daniel Leu
ParticipantThe issue you encountered is that the prompter function is not blocking. So when you access the variable after the prompter call, this access happens before you have a chance to enter anything.
I was struggling with this for a while when it was first introduced. This is what I use now:
function textPrompter(title, text="") { return new Promise(function(resolve, reject) { let prompter = Prompter.new(); prompter.cancelButtonTitle = 'Cancel'; prompter.continueButtonTitle = 'Continue'; prompter.addParameter(text,'prompterVar') .show(title, ((status) => { if (status == false || prompterVar == undefined) { reject('Cancel'); } else { resolve(prompterVar); } })); }); } async function prompterTest() { // Check textPrompter try { await textPrompter("Title", "Enter text") console.log(prompterVar + " entered"); } catch (errorText) { console.log('cancelled textPrompter: ' +errorText); } finally { console.log(scriptName+": Script finished at " + new Date); } } prompterTest();Hope this helps!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksApril 8, 2021 at 4:44 PM #44088In reply to: Adding a string to a phone number.
Daniel Leu
ParticipantYeah, you need a script using the Javascript API for that.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksApril 8, 2021 at 8:49 AM #44082In reply to: Scripts and searching
Sam Moffatt
ParticipantThere is an extra bit of linking metadata that would be tracked. 1:M/M:M Link to Form fields create an internal link record for each link you make and the JOIN records create a materialised search with similar data (not 100% on the internals though). There is a cost per record link but in general it’s in the order of a few hundred bytes per link and no more than a kilobyte. I think because of the underlying implementation details, the JOIN is probably a little more space efficient because some of the linking data is persisted in the records on each side.
In my own forms, I use a JOIN link to pull the grandchildren of that record into it. The two records share a common key field (actually a calculation that joins three fields together, see the screenshot) and then the JOIN field uses the calculation field on both sides. You could set up a calculation field that uses the value of another field or also uses the 1:M link to get values.
The other aspect is that once you have a JOIN field, you can use scripting to iterate through the records in the JOIN field and have the script add them to the 1:M field. Pseudocoding a little:
let joinRecords = record.getFieldValue('fld-joinfieldid'); for(let joinRecord of joinRecords) { record.addRecordToField(joinRecord, 'fld-1mfieldid'); } document.saveAllChanges();Basically once TF has done the heavy lifting to find the records to link, add in the links via scripting. An extra step could be a script that scans all of the records or perhaps a saved search to limit the candidate set (again, make Tap Forms do the work to find the records). Then all of your old records will look like new records :D You can keep the JOIN field, hide it so you don’t see it but when you do an import it’s there with what you need ready to go.
Attachments:
You must be logged in to view attached files.April 7, 2021 at 11:56 PM #44078In reply to: Keep field the same value from previous
Victor Warner
ParticipantSam,
Would it be possible for you to make one of your videos to demonstrate how to use the prompter interface – as what you write in the last paragraph is something I would be very interested in doing if I could work out how to implement the relevant JavaScript.
April 7, 2021 at 11:46 PM #44077Topic: Feature updates request
in forum Using Tap Forms 5Victor Warner
ParticipantI would like to request the following improvements to the user interface:
1. For layouts – would it be possible to add a (menu) commands to go ti the default (first) layout and to the last layout in addition to the go to the next and previous layouts? In the same way for Records.
2. For saved searches – would it be possible to add a menu option to go to a specific saved search following the postings and Sam Moffat’s suggestion at: https://www.tapforms.com/forums/topic/scripts-and-searching/#post-44036.
April 7, 2021 at 11:10 PM #44075In reply to: Keep field the same value from previous
Sam Moffatt
ParticipantIf it’s a single field, or set of related fields for something like seller, I’d consider having a seller form and using a link to form field to your inventory form. Then you open the linked inventory form from the seller and that linked field is retained for each new record you create.
If you have multiple unique fields then I agree with Daniel that a simple script that creates a new records and copies the fields from the current record to the new one and then navigates to it would make sense.
One other trick I use for bulk importing is to use the prompter interface to present the subset of fields that I need to edit and put that into a loop. That can give you a much faster data input system because you can enter the data, hit enter to submit and then have it popup again to input the next record. I use prompters to create records in a few places where I don’t need to see the record immediately after creation as generally the prompter flow is a little quicker than going into a record in a link to field use case.
-
AuthorSearch Results