Tap Forms app icon half
Tap Forms Forum text image
Blue gradient background

Exchange tips and ideas with the Tap Forms community

Search Results for 'script'

Viewing 15 results - 1,936 through 1,950 (of 2,989 total)
  • Author
    Search Results
  • #40495
    Brendan
    Keymaster

    Hi 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

    #40486

    In reply to: Invoicing

    Sam Moffatt
    Participant

    Assuming 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.

    #40482

    In reply to: Invoicing

    Vera Milosavich
    Participant

    BTW: 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!

    #40479
    Sam Moffatt
    Participant

    Just 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.

    #40474

    In reply to: Compound calculations?

    Vera Milosavich
    Participant

    Thank 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.

    #40468
    Brendan
    Keymaster

    Hi 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

    #40462

    In reply to: Compound calculations?

    Brendan
    Keymaster

    Hi 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.

    #40454
    Vera Milosavich
    Participant

    Is it possible to nest calculation formulas? For instance:

    IF ((A=B OR C=D AND E=F);X;Y)

    I don’t see any OR or AND type 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.

    #40452
    Sam Moffatt
    Participant

    Nothing wrong with the script, just saying you can format it a little better on the forum :)

    #40451
    Sam Moffatt
    Participant

    I 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.

    #40450
    Rainer
    Participant

    hi 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 code

    thanks
    Rainer

    #40444
    Victor Warner
    Participant

    Sam,

    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.

    #40439

    In reply to: Invoicing

    Brendan
    Keymaster

    Hello 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.
    #40430
    Sam Moffatt
    Participant

    The problem is that replace is 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 then replace would work fine because it’ll coerce the number into a string form.

    #40426
    Rainer
    Participant

    Hello all
    found a way to get this done with this script
    I thought I’d post it here incase it helps someone else

    function 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();

Viewing 15 results - 1,936 through 1,950 (of 2,989 total)