Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
May 6, 2020 at 8:33 PM #40495
In reply to: formula showing sum of all records
Brendan
KeymasterHi Wolfgang,
Sure. You can get that.
In the JavaScript API docs there’s this function:
var total = form.getTotalOfField(field_id);That’ll do it. It returns the same value as you see displayed at the bottom of the records list view.
Hope that’s what you’re looking for.
Thanks!
Brendan
Sam Moffatt
ParticipantAssuming you’ve set up your invoices with a link to form or table field in them for the individual line items, you can generate a script field that calculate what you need. The “Child records loop” snippet is a good place to start, you can use that to get the values of the child records and do what ever calculation you need.
I think one of the areas that Tap Forms is a little limited in is the reporting functionality with respect to nested elements. The custom layouts work well for single records and setting up simple labels but when it comes to building a single layout that could flow to multiple pages naturally based on child content, that just isn’t a thing. Getting something like that right in a generic sense is hard and would require building a new layout engine from scratch, it’s not the sort of thing I’ve seen outside of the expensive databasing products. I’ve spent a lot of quality time with page layout platforms and it can quickly get out of hand when you start to drill down into formatting, fitting items on pages, how you handle overflowing subcontent (e.g. should a child record be split apart or should it always be together?) and issues around odd/even page formatting. Very quickly printing things becomes…interesting.
Vera Milosavich
ParticipantBTW: I did NOT mean to imply TapForms is NOT excellent. So far it is the best of the home- and small-business use database I’ve tried. But summaries are critical for me.
Maybe I’m approaching summaries in the wrong way…
I’m still trying to figure out how a lot of the fields and properties work. Is there a way to create a separate field that can display a sum based on matching criteria, like SUMIF() and SUMIFS() in Excel or Numbers? If you could implement those kinds of formulas, my problem might be solved!
Or is it possible to collapse the line items of a summary when displayed on another invoice — or even in the spreadsheet view because sometimes I really ONLY want to see the subtotals and not every transaction.
Or is there a way to copy/paste group summaries so I can paste them into an invoice? It would be clunky, but it’s better than typing it in.
Is any of this something a script can do NOW? If so, maybe I can get help with that down the line. I’m not excited to learn scripting, but if I can solve this one problem, I think I’ll be over the transition hump.
Thanks!
May 5, 2020 at 11:17 AM #40479Topic: Humble Bundle Sale: Javascript Definitive Guide
in forum Script TalkSam Moffatt
ParticipantJust thought I’d post over here that Humble Bundle currently have a sale a selection of books from the O’Reilly Definitive Guide series. At the $1 tier is the Javascript book and I know folks have mentioned wanting to pick up more Javascript. I’ve not personally read this book but in general I’ve found O’Reilly’s books to be well written and I have a good selection of their books. At a dollar, that also helps charity too, I think it is at least worth a look to see.
May 5, 2020 at 1:51 AM #40474In reply to: Compound calculations?
Vera Milosavich
ParticipantThank you for the info. I did look through the manual but either I overlooked that or misunderstood the use.
I have no doubt that scripts can do much more, but I can’t devote the amount of time to learning this for just a handful of uses.
May 5, 2020 at 12:57 AM #40468In reply to: how to use dateadd in a script
Brendan
KeymasterHi Rainer,
Take a look at your post above again. I added the `
code` back ticks to show you what your script looks like formatted nicely. Sam and Daniel were just trying to help so that it’s easier to read your code.Here’s an example of a single line piece of code with back ticks:
var first_name_id = 'fld-......';and here’s a multi-line one:
var first_name_id = fld-.....'; var first_name = record.getFieldValue(first_name_id);We’re all here to help and share ideas.
Thanks,
Brendan
May 5, 2020 at 12:32 AM #40462In reply to: Compound calculations?
Brendan
KeymasterHi Vera,
With an IF() expression, you can use
&for AND and~for OR.so
IF((A=B ~ C=D & E=F); X; Y)The operators are mentioned in the Calculations topic in the online user manual:
https://www.tapforms.com/help-mac/5.3/en/topic/calculation
But for complex operations I usually prefer to use a Script Field instead of a Calculation Field. You can do so much more with Script Fields.
May 4, 2020 at 5:09 PM #40454Topic: Compound calculations?
in forum Using Tap Forms 5Vera Milosavich
ParticipantIs it possible to nest calculation formulas? For instance:
IF ((A=B OR C=D AND E=F);X;Y)I don’t see any
ORorANDtype functions in calculations. Is there a different way of accomplishing this?I’m utterly clueless in Javascript so I’m hoping that isn’t the only answer. If it is, I’m afraid I won’t be able to set up half the calculations I need.
May 4, 2020 at 2:59 PM #40452In reply to: how to use dateadd in a script
Sam Moffatt
ParticipantNothing wrong with the script, just saying you can format it a little better on the forum :)
May 4, 2020 at 10:52 AM #40451In reply to: Whether to use a script or a calculation?
Sam Moffatt
ParticipantI think you can do it in either a calc or a script but I feel a script would be easier to manage and debug.
Create a new script field, open up the editor and you should get something like this:
function Final_Amount() { // Replace with your own code var hello_world = "Hello World!"; return hello_world; } Final_Amount();Wipe out the middle bits so it looks a little closer to this:
function Final_Amount() { } Final_Amount();Put your cursor in the middle and use the editor to import all of the fields you’re interested in (3,5 and 7; 8 will be your script field). It should look something like this:
function Final_Amount() { var amount_due = record.getFieldValue('fld-1234'); var amount_paid_minus_izettle = record.getFieldValue('fld-1337'); var amount_paid_minus_bank_charge = record.getFieldValue('fld-4321'); } Final_Amount();The exact names and ID’s will be specific to you. Then you just need to convert the logic you wrote into Javascript which is easy enough:
if (amount_paid_minus_izettle == 0 && amount_paid_minus_bank_charge == 0) { return amount_due; } if (amount_paid_minus_izettle > 0) { return amount_due - amount_paid_minus_izettle; } if (amount_paid_minus_bank_charge > 0) { return amount_due - amount_paid_minus_bank_charge; } return 0;This needs to be embedded into the function, so your final script looks a little like this:
function Final_Amount() { var amount_due = record.getFieldValue('fld-1234'); var amount_paid_minus_izettle = record.getFieldValue('fld-1337'); var amount_paid_minus_bank_charge = record.getFieldValue('fld-4321'); if (amount_paid_minus_izettle == 0 && amount_paid_minus_bank_charge == 0) { return amount_due; } if (amount_paid_minus_izettle > 0) { return amount_due - amount_paid_minus_izettle; } if (amount_paid_minus_bank_charge > 0) { return amount_due - amount_paid_minus_bank_charge; } return 0; } Final_Amount();That should do mostly what you want, I’d go for a script because it’s a little easier to debug and build up plus easier to format out than the calculation fields.
May 4, 2020 at 10:51 AM #40450In reply to: how to use dateadd in a script
Rainer
Participanthi Sam thanks for replying
is there something I’ve done wrong in my script?Sorry I’m very new to coding in javascript and I’m not sure what you mean
“You can use backticks to wrap your codethanks
RainerMay 4, 2020 at 4:09 AM #40444In reply to: Script error – what it means?
Victor Warner
ParticipantSam,
Thank you for the response.
…are you expecting to replace a substring of numbers to a new value in your number field?
Yes that is right.
I can see there is a string function in JavaScript but because I do not know JavaScript, could you amend the code so that it is possible to search for one or more numbers? I would be very grateful.
Brendan
KeymasterHello Vera,
What was it about the Invoices sample database document that didn’t help? The description of your requirements sounds awfully familiar to the Invoices sample. There’s a Clients form (yes, like a table), a Products form, and an Orders form, which is essentially your invoices.
You can filter records based on any fields that are in the parent form. I call these filters Saved Searches. You can even have different sort orders and field columns displayed for each Saved Search.
You can see on the sample screenshot attached that also shows the sub and grand totals.
There’s an advanced find and replace function in the Mac version which would let you do a global update. Plus there’s other tools for that sort of thing too such as the fill up/down and drag fill function, like you get in Excel or Numbers for copying the value of one cell down to others in the same column.
Hope that helps a bit.
Thanks!
Brendan
Attachments:
You must be logged in to view attached files.May 2, 2020 at 10:47 PM #40430In reply to: Script error – what it means?
Sam Moffatt
ParticipantThe problem is that
replaceis a method of a string which in Javascript is an object. A number is a different type of object and doesn’t have a replace method because it doesn’t make sense.To help you along, are you expecting to replace a substring of numbers to a new value in your number field? To do so, you’d have to convert the number to a string (easy way is to use an empty string and add your variable to it, e.g.
'' + myvar) and thenreplacewould work fine because it’ll coerce the number into a string form.May 2, 2020 at 3:27 PM #40426In reply to: how to use dateadd in a script
Rainer
ParticipantHello all
found a way to get this done with this script
I thought I’d post it here incase it helps someone elsefunction Try2() {
var call_date_id = ‘fld-9b94287517344436995393d16d0f5d7e’;
var mydate = record.getFieldValue(call_date_id);
var startdate = new Date(mydate);
var enddate = new Date(startdate);enddate.setHours((startdate.getHours() + 1));
console.log(enddate);
}
Try2();
-
AuthorSearch Results