Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
April 13, 2021 at 7:45 PM #44147
Sam Moffatt
ParticipantDo you have fields scripts that work on the record? There might be a data race with the layout renderer and something mutating the record state?
April 13, 2021 at 9:45 AM #44146Topic: Pasting large script causes TapForms to hang indefinitely
in forum Script Talkcf
ParticipantHere’s an example of a script that will cause this:
https://raw.githubusercontent.com/cfilipov/tfscripts/master/cheerio.js
You can try copy-pasting the contents of that script directly in the TapForms script editor and it will beach ball forever. It’s possible if I waited long enough whatever was blocking the main thread would finish but after waiting a long time I just killed tap forms (which of course does not save the script). If I had to guess it’s the syntax parsing of the js causing the hang.
As a workaround I used Sam’s script manager to download the script and add it without using the editor UI. This works for getting the script in tap forms and it’s runnable, however, if you try to open the script to edit/view it will also hang just like before.
April 13, 2021 at 12:16 AM #44139In reply to: Adding a string to a phone number.
Sam Moffatt
ParticipantYou can hide the script field and it’ll keep working when ever it’s dependent fields are updated. Something simple to take out the +44 assuming it’s at the start of the field:
record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/^\+44/, '').replace(/[^0-9]/g, '');The
^\+44basically says match the start of the string (the^character), match a plus sign (the\+piece,+has special meaning normally so needs to be escaped) and then match “44”. If the+44isn’t at the start then remove the^character (e.g./\+44/) to just replace that string.I chain this as two
replacestatements just because it makes things a little clearer what is going on (e.g. you’re getting the field value, then you’re replacing the country code and then you’re making everything a number).Regex 101 link: https://regex101.com/r/hPF4kb/1
Regular expressions can be a bit of a challenge to learn but if you’re doing string manipulation they’re an invaluable tool in many languages, including Javascript!
April 12, 2021 at 11:41 PM #44138In reply to: Adding a string to a phone number.
Andrew Drapper
ParticipantThank you so much.
Works like a dream. I could fight on trying to parse the off +44 that some records have, but I think I will just hand modify as they come up.
Presumably, I now hide the script field and let it do its stuff in the background?
Andrew
April 12, 2021 at 9:54 AM #44132In reply to: Adding a string to a phone number.
Andrew Drapper
ParticipantSorry,
I probably need to do a bit more reading into the manual but I now have
function SMS() { var mobilephone = record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/[^0-9]/g, ''); var SMS = mobilephone + "@textmagic.com"; //console.log(SMS); return SMS; const email_id = 'fld-d52d76de4eed468f9119a49b50a47f0d'; record.setFieldValue(email_id, SMS()); document.saveAllChanges(); } SMS();But though I do get a nice “07***726@textmagic.com” in my SMS Script field, it does not place anything in the email field.
April 12, 2021 at 12:50 AM #44128In reply to: Adding a string to a phone number.
Andrew Drapper
ParticipantWith some fiddling, I got this to work
function SMS() { var mobilephone = record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/[^0-9]/g, ''); var SMS = mobilephone + "@textmagic.com"; console.log(SMS); return SMS; } SMS();But I now have this number in a script field and therefore can not click on the send email symbol.
Can I now past this value into an email field?
April 11, 2021 at 12:30 AM #44122In reply to: Scripts and searching
Sam Moffatt
ParticipantWhen you’re using a JOIN field, both sides are M:M relationships because it doesn’t know if it is singular or not. The calculation field there can’t handle the M:M relationship properly in the same way it it can being on the child side of the 1:M where there is only one entry. The solution for that is generally a script that just pulls out the first entry from the field.
I use this construct to gather all of the child entries and join them together:
var client_contact_details = record.getFieldValue('fld-beaf858dba7d4014b89722411ebcbd3f'); if (client_contact_details) { client_contact_details.map(r => r.getFieldValue('fld-0d5ab10b7374418bac721d6446c81b73')).join(' '); }First line gets the child records from the link to form, second line checks if we got a value back (avoid undefined error, mostly harmless but some defensiveness doesn’t hurt), the third line is a little bit to unpack though. The
mapfunction is like a short hand of a for loop to run a single function. In this case we’re going through each of the records inclient_contact_detailsand “mapping” that value (a Tap Forms record) to the value of the fieldfld-0d5ab10b7374418bac721d6446c81b73. The last part of that line basically says to convert the array to be “joined” by spaces.For the JOIN count for documents, I did
COUNT( Notarised documents - Join::Type of document )and that seemed to work properly for me giving me a count of two.April 10, 2021 at 2:52 PM #44120Sam 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(); -
AuthorSearch Results