Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
January 16, 2019 at 2:51 PM #33463
In reply to: Script linked table loop
Brendan
KeymasterHi Gianantonio,
There’s a snippet that does this for you.
Just tap on the Child Records Loop snippet when you have a child field selected on the Script Edit window. If you’re using iOS, tap the snippet first, then Tap Forms will ask you which field you’d like to select. When you select the field, Tap Forms will generate the code for you that loops through the Table field records.
Also you can double-click on a Table field or Link to Form field header and Tap Forms will write the code for you to get the child records.
January 16, 2019 at 1:38 PM #33462Topic: Script linked table loop
in forum Using Tap Forms 5Gianantonio Fiannacca
ParticipantPlease, can you post a little example how looping a linked table?
I don’t found field reference in a main record to identify linked table; instead I see fields in a linked table. But I don’t know how loop secondary records table.
Thank,
GianantonioJanuary 14, 2019 at 8:14 PM #33432In reply to: Script to delete record
Brendan
Keymasterform.selectRecord(someRecord)is for telling Tap Forms to select a record. It’s useful when you use JavaScript to add a record to your form.For deleting a record, you need to get the record first before you can delete it.
If you want to delete a single record in a loop, you have to first get the records from the form. Then loop through them, check the record to see if it’s the right one to delete, then call the function to delete it.
var records = form.getRecords(); var field_id = 'fld-....'; for (var index = 0, count = records.length; index < count; index++){ var aRecord = records[index]; var field_value = aRecord.getFieldValue(field_id); if (field_value == 'some value') { form.deleteRecord(aRecord); } } form.saveAllChanges();Something like the above should work but it has to be modified for your own form of course.
January 14, 2019 at 7:44 PM #33430In reply to: Grab data from url?
Brendan
KeymasterHi Steve,
Sure, you can do that using the Script feature. You need to know a bit of JavaScript, but there are functions to get data from a URL.
See the docs for the JavaScript API:
https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api
Also there’s a sample script on this page that shows you how to get JSON data from a URL:
January 14, 2019 at 7:29 PM #33429Topic: Script to delete record
in forum Using Tap Forms 5Gianantonio Fiannacca
ParticipantHy i se in javascript Api this:
form.deleteRecord(someRecord);
Can you telo me a little ex?
There is also a form.selectRecord(someRecord)I dont understand what insert in someRecord
In a script loop i want delete single record
Thank
January 12, 2019 at 12:39 PM #33382In reply to: How to handle multiples and analysis?
Brendan
KeymasterHi Steve,
1. No, Tap Forms doesn’t have graphing ability directly in the app. You’ll have to export the data and import into Numbers or Excel or some other app that supports that.
2. The Table field (and Link to Form fields) have a different structure than the main form your exporting. So that’s why they’re exported as separate CSV file.
3. You can add fields on the fly, but they’ll apply to all the records in the form. When you edit a form, you’re simply editing the form’s template that will be displayed for every record within that form. So there’s no function for one record to have one set of fields and another record to have a different set of fields.
4. This happens automatically when using a Link to Form or Table field obviously as you add additional records to the relationship. That’s because even in a Table field, the sub-fields apply to every sub-record within the Table field. Same for Link to Form fields.
One solution of course is to just estimate how many bananas you will ever need and add as many fields that you need to handle the maximum case.
Or if you used a One to Many Link to Form field on your parent “Activity” form, then you could add a Calculation or Script field in your child “Bananas” form that extracts certain information from the parent Activity form and displays it. That way you could just go right to the Bananas form and export all of that as a CSV file for analysis in Numbers or Excel. Each Banana record would contain that bit of information you extracted from the parent Activity record. Hope that makes sense.
Thanks!
Brendan
January 10, 2019 at 12:43 PM #33357In reply to: Search on inverse link fields?
Brendan
KeymasterHi Greg,
There’s no function to search a parent form for any values contained in a related form.
However, you can workaround this by using either a Script field or a Calculation field.
On your form B, add a Calculation field. Edit the formula and choose a field from the list of fields that show up that are contained within the parent form A. Any field will do. Then you can add a Saved Search that checks to see if the value of the calculation field is empty or not.
Hope that helps.
Thanks,
Brendan
January 10, 2019 at 3:21 AM #33354Victor Warner
ParticipantBrendan,
Thank you very much! Problem solved.
I will hide the script field (as you have suggested), but just to know for the future, will that script field always show a ‘1’ regardless of what is in the other fields?
January 10, 2019 at 2:51 AM #33351Victor Warner
ParticipantBrendan,
Thank you for the explanation.
I have tried to follow the approach you outlined. But it appears not to work: the script field and the Time Charge For fields are not updated.
I created:
1. Time spent Field = type: number
2. Time spent to time charged for Field = type: script.
3. Time charged for Field = type: number.The Time spent to time charged for Field only shows a “1” regardless of what I put in the Time spent Field and the Time charged for Field is not updated.
Attached is the Form. Could you let me know where I have gone wrong?
Attachments:
You must be logged in to view attached files.January 9, 2019 at 1:55 PM #33344Brendan
KeymasterHi Victor,
Yes. You can do this with a Script field.
In a Script field when you use the
record.getFieldValue(field_id)function, Tap Forms begins watching that field for any changes made to it. It executes the script if the value of that field changes.So by adding a Script field, you could have Tap Forms copy the value from your Time Spent field into your Time Charged field. Now normally a Script field will display its contents in your form, but recently I added a Hide field function to Tap Forms 5.3 which will let you hide any field. So you could have this hidden Script field that’s just watching what’s going on with your form and running automatically when fields the script is watching change.
Thanks!
Brendan
January 7, 2019 at 2:20 PM #33309In reply to: How to display a text calculation in upper case
Brendan
KeymasterHi Victor,
You would need to use a Script field instead of a Calculation field to be able to do something like that.
Here’s a sample that might help:
var first_name_id = "fld...."; var last_name_id = "fld..."; var middle_name_id = "fld..."; var firstName = record.getFieldValue(first_name_id); var lastName = record.getFieldValue(last_name_id); var middleName = record.getFieldValue(middle_name_id); var fullName = ""; if (middleName) { fullName = firstName + " " + middleName + " " + lastName; } else { fullName = firstName + " " + lastName; } var result = fullName.toUpperCase(); result;January 6, 2019 at 2:48 PM #33253Brendan
KeymasterYou want a Script field just as you’ve created. Because you’re wanting to display the first passport information in the parent form.
Here’s the exact script you can just copy and paste into your Passport Script:
// declare the field ID for the passport field. Select the field and click the ID button to get the field ID. var passport_id = 'fld-bb12ade9886146818f0cee47af4a36d5'; var result = ''; // From the currently selected record, get the list of records from the passport field. var passportRecords = record.getFieldValue(passport_id); // if we have any passport records, get the passport information. if (passportRecords.length > 0) { // Get the very first passport record from the list of passportRecords. var firstPassportRecord = passportRecords[0]; // declare the passport field ids. var passport_number_id = 'fld-fc5f7b08aa244466919fd400714ffa6b'; var date_of_expiry_id = 'fld-b73ebd82a8b2479882e9d2fc5b161ff9'; var country_id = 'fld-b502438543564135859a133912994d3f'; // From the first passport record we grabbed above, get the passport number value. var number = firstPassportRecord.getFieldValue(passport_number_id); var expiryDate = firstPassportRecord.getFieldValue(date_of_expiry_id); var country = firstPassportRecord.getFieldValue(country_id); // and do whatever you want with the values. What you had is almost what you needed: result = "having a " + country + " passport, with a date of expiry of " + expiryDate.toLocaleDateString() + " and a passport number " + number; } result;January 6, 2019 at 9:59 AM #33238Victor Warner
ParticipantBrendan,
Thank you very much for explaining the script, and I can now understand the logic of it but I am having difficulty applying it my database.
As being completely new I am still not clear whether I should be creating
1. a new field of the type script; or
2. a Form scriptIf a new field script, should I creating a field in the Client Contact form or the Passport form?
Attached is a backed up version of the Forms to show how it actually looks.
Attachments:
You must be logged in to view attached files.January 5, 2019 at 5:57 PM #33210Victor Warner
ParticipantBrendan,
Thank you for the reply.
As I mentioned Javascript is unknown me (but it is clear I will have to learn it), but in the meantime I wonder if you could provide some explanation for each of the lines of code you provided (to try to understand how to relate the code to the example I gave in my initial post):
var passport_field_id = ‘fld-….’;
var passportRecords = record.getFieldValue(passport_field_id);
if (passportRecords.length > 0) {
var firstPassportRecord = passportRecords[0];
var number_field_id = ‘fld….’;
var number = firstPassportRecord.getFieldValue(number_field_id);// and do whatever you want with the values/
}
And I in particular how I write the code for
// and do whatever you want with the values/
if I wished to produce:
“having a ” + [country] + ” passport, with a date of expiry of ” + [date of expiry] + ” and a passport number + ” ” [passport number]
Any help you could provide would be very gratefully received.
January 3, 2019 at 5:49 PM #33134In reply to: Advice on script triggering
Brendan
KeymasterYes, it would have to be a Script Field and not a Form Script. That’s because Form Scripts all are run manually whereas a Script Field is run when a value it references changes.
yes, the
record.getFieldValue(field_id)reference is what tells Tap Forms that script is referencing that field, so when that field changes its value, run the script that references it. -
AuthorSearch Results