Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
May 15, 2020 at 2:21 AM #40606
In reply to: Display linked content
Brendan
KeymasterHi Vera,
There are a couple of problems with your script.
First off, you haven’t defined
link_invoiceanywhere, yet you’re referencing it.Also, you haven’t defined
index, yet you’re using it as an array reference.Take a look at the Child Records Loop snippet. If you select your invoice number field from your Linked form on the Fields list on the left, then double-click on the Child Records Loop snippet at the bottom-left of the Script Editor, Tap Forms will write a function for you to loop through all of the records in your
link_invoiceLink to Form field.Since it’s a many-to-many, there can be multiple values for Invoice Number.
But if all you want is the first one, then you could do:
function get_invoice_number() { var invoice_number = ''; var link_invoices_id = 'fld-.....'; var link_invoices = record.getFieldValue(link_invoices_id); if (link_invoices.length > 0) { var first_invoice = link_invoices[0]; var invoice_number_id = 'fld.....'; invoice_number = first_invoice.getFieldValue(invoice_number_id); } return invoice_number; } get_invoice_number();You of course have to replace ‘fld….’ with your own field IDs, which you can get from the Fields list on the left.
May 14, 2020 at 9:45 PM #40604Topic: Display linked content
in forum Using Tap Forms 5Vera Milosavich
ParticipantI have two linked forms (from different sources): TRANSACTIONS and INVOICES
Both of them have fields named month-year and and invoice-number
In TRANSACTIONS, month-year is a calculation field (based on a date field in the same form).
In INVOICES, month-year and invoice-number are text fields (not number or date) and I type in the info when I create an invoice. Both are unique values across all records. Everything is fine up to this point, but…I want the invoice-number field in TRANSACTIONS to display the invoice-number from INVOICES for all TRANSACTION records where month-year match. I tried both a calculation and a script. The calculation inserts a count formula, which is not what I want. The script gives me an error when I test it inside the script editor. I attached a screen shot of the script & error.
The forms are linked by month-year — one to many — but I tried the other linking options and they were no better.
I’m sure my logic is not what it should be due to my JS illiteracy. Can you tell me what I’m doing wrong?
Attachments:
You must be logged in to view attached files.May 14, 2020 at 12:23 AM #40596In reply to: Return into form field, data from linked form?
Sam Moffatt
ParticipantIf it’s the way I have it set up, you don’t even need to use a script field any more. A regular calculation field will work and all you’ll have to do is select the field from the field list on the left. Easy peasy!
Technically you could also do something similar with scripting and a little bit of chaining:
record.getFieldValue('fld-lnkfromform').getFieldValue('fld-targetfield');If there isn’t a parent record set, it’ll internally error out but that should be mostly harmless as a single line.
Brendan
KeymasterThe code above is Objective-C. But the
ifstatement looks pretty much identical to how it would in JavaScript. Dots are just used to get the value of an object. For example, you’re Vera. That’s yourfirst_name. Vera is aPerson. So to get your name I can sayperson.first_nameand I would be given the first name of you :)Square brackets aren’t too scary either. They just help you to index into an array. You’ve seen an Excel spreadsheet I’m sure. They have row numbers on the left. In fact, the multi-column list view shows row numbers in Tap Forms. To get a value from an array you would just say
people[10]. That would give you the 10th person from the people array :). Really not too scary if you think about it.Vera Milosavich
ParticipantIs that algorithm javascript? If so, THAT’S the kind of scripting I understand — except maybe the first 3 lines. Whenever it gets into arrays or uses “.” or square brackets, I get lost. I’m not a programmer.
Yes, send PDFs now (with my FM solution), but I would like him to be able to see the info as up-to-date as I have it. Mine may be a few weeks old as I only import records at the start of the month (due to FM reboot nuisance). But if TF import and syncing from my iPad works well (that’s where I do most of my record-keeping), I might import more frequently. So thank you for that answer.
May 13, 2020 at 11:34 AM #40587In reply to: Programmatically set record color
Brendan
KeymasterHi Oliver,
Although you can colour fields and values in Tap Forms, they are global settings on the Field object itself. So any change made to them will apply to every record, not just for a particular record.
But there is a
labelColourandvalueColourproperty on the Field object that can be accessed from a Script.Thanks,
Brendan
May 13, 2020 at 10:20 AM #40585In reply to: Not a question but a comment….
Vera Milosavich
ParticipantHi Brendan,
I had no idea TF has been around for so long. I never heard of it until a few weeks ago when I started trying out alternatives. And I’m sorry if I gave the impression that you should t be using JavaScript. It wasn’t what I meant at all. I fully understand if not for JS, this would be a far more expensive program. I also know JS is everywhere, and I’ve heard it was easy to learn, but it hasn’t been so for me. That’s what I was getting at. I bought a few books about 15 years ago and tried learning but finally gave up. As close as I get to programming now is HTML, CSS, and spreadsheet formulas, and I know these aren’t programming. But I’m willing to take small bites of JS.
BTW: May I suggest you set up a separate forum board for feature requests? It might be a good way for people to let you know what they’d most like and perhaps vote on what others like. Likewise, if it’s something that already exists, it might be a good way to get the word out.
Thanks again!
May 13, 2020 at 8:56 AM #40581In reply to: Script error – what it means?
Sam Moffatt
ParticipantThere is a
search.getRecords()to get records from the current search. It has a few methods, checkout the JavaScript API page for more details (towards the bottom of the page).May 13, 2020 at 6:56 AM #40578In reply to: Script error – what it means?
Victor Warner
ParticipantOn running this script it works on all the records in a database.
Running the script on a filtered set of records (through Find (Command + F) or an Advanced Search) does not limit its operation to the filtered set of records.
Is it possible to make the script work only on a filtered set of records?
May 13, 2020 at 2:01 AM #40576In reply to: Return into form field, data from linked form?
Brendan
KeymasterBy the way, you have to replace the field IDs with your own proper field IDs.
But since you used Sam’s idea and switched to a One to Many Link Type, then you could also simplify the above script to:
function getCompany() { var company = ''; var contact_record = record.getFieldValue('fld-abc123.......'); if (contact_record) { company = contact_record.getFieldValue('fld-xyz987......'); } return company; }; getCompany();By the way, I’ve just typed in this code and haven’t actually run it since I don’t have your form. So it might not work out of the box.
May 13, 2020 at 1:54 AM #40575In reply to: Return into form field, data from linked form?
Brendan
KeymasterFor the Child Records Loop snippet to work properly, you need to first select a child field from the Fields list on the Script Editor.
Then double-click on the Child Records Loop snippet.
You’ll get something that works then.
However, since you have a many-to-many relationship, you have to think about which customer record you actually want. The Child Records Loop snippet will loop through all of the child records. The
// do somethingcomment means this is where you want to do some custom programming.But in your case, if all you want is the first record, then you don’t really need the loop itself. You can just grab the first child record.
So something like this:
function getCompany() { var company = ''; var contact_records = record.getFieldValue('fld-abc123.......'); if (contact_records.length > 0) { var first_contact = contact_records[0]; company = first_contact.getFieldValue('fld-xyz987......'); } return company; }; getCompany();So this will pick out the very first record from the contacts Link to Form field and return the company. It will appear in your Company Script field.
I hope that makes sense.
May 13, 2020 at 1:49 AM #40574In reply to: Return into form field, data from linked form?
David Oxtoby
ParticipantThank you, i also tried Sam’s suggested about reversing the way i’m linking, and it gets me the desired result of the company name etc in the summary side-panel, so thank you for that. But having the code snippet would be great as well, if nothing else, as an aid to help me learn how to use the scripting, as this looks to be a great feature with loads of potential, once i get my head around it. Thank you everyone for speedy and helpful response.
May 13, 2020 at 1:41 AM #40571In reply to: Return into form field, data from linked form?
David Oxtoby
ParticipantThx for that Sam, i’m a bit new to the whole scripting thing, i see how to make the Company field into a script field, and then add in the snippet of code for Child Records Loop, but if gives me the following the editor.
function recordsLoop() { var parent-field-name_id = 'parent-field-id'; var booking_date_time_id = 'fld-8fb5dadd45ee4276b4813669aeef34e3'; var parent-field-name = record.getFieldValue(parent-field-name_id); for (var index = 0, count = parent-field-name.length; index < count; index++){ var booking_date_time = parent-field-name[index].getFieldValue(booking_date_time_id); if (booking_date_time) { // do something } } return; } recordsLoop();how do i then tell it to loop through my customer form/table to pull out the first record Company Name?
sorry to ask the basics on this, but it’s a long time since i programmed, and back then it was COBOL! eek showing my age.
May 13, 2020 at 1:25 AM #40568In reply to: Not a question but a comment….
Brendan
KeymasterHi Vera and Chris,
Thanks so much for your vote of confidence for Tap Forms. I am pretty much always working on Tap Forms new features and bug fixes. I’ve been working on it since 2008. So it’s been around a long time and I never tire of it. Sure I take a day off here and there from working on it, but I always respond to customer emails and this forum every day. Often at night after my family has gone to sleep. Especially during this time when everyone is around, it’s sometimes tricky to get time to work during the day. But I’m a night owl anyway, so this works for me. I imagine I’ll still be working on Tap Forms for the next 20 or 30 years!
I’m glad that you were able to make a solution with Tap Forms that works for you.
The use of JavaScript as a scripting engine was a decision I made because JavaScript is relatively easy to learn and program, and it’s built-in to macOS and iOS. Building your own scripting engine is a massive effort that a one-person operation like myself just couldn’t possibly do in any reasonable amount of time. FileMaker would have built up their scripting engine over many many years with a big team of engineers working on it. Since Apple already provided the JavaScript Core Framework, I chose to use that. So far it has worked out very well for Tap Forms, even if there’s a bit of a learning curve for some people. The snippets that I have can really help you to learn some of the basics of what you need in Tap Forms to get going. Plus the Script Talk forum on my website can be very useful to see how other customers are writing scripts. And there are some fabulous customers and Tap Forms beta testers on that forum who really know their JavaScript stuff.
Thanks!
Brendan
May 13, 2020 at 1:24 AM #40566In reply to: Return into form field, data from linked form?
Sam Moffatt
ParticipantIf you make Company a script field, you can use the
Child Records Loopto iterate over theCustomerLink to Form and extract the name. The reason is that you can technically have multiple customers so you need to iterate overall of them and process them.That said I’d probably flip the model a little. You’ve got a Link to Form there and I’m guessing it’s a many to many or M:M type. If for a given venue booking there is only one customer, I would recreate the field as a Link to Form One to Many (1:M) going from the Customer form to the Bookings form with
show inverse relationshipticked. What this will do is change the type of control you see on your booking form to be the single record selection layout which may or may not be desirable for you. It’s like the single column list view sort of rendered into your form. The advantage of flipping the relationship is you can easily use a calculation field to pull out records. Since the booking record will only ever have a single parent, you can create a calculation field to pull the parent record’s values out (or multiple calculation fields for each field you care about). Make sure when using a calculation field to update the default output type from number to text otherwise it’ll appear empty and you won’t know why. -
AuthorSearch Results