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,952 total)
  • Author
    Search Results
  • #40299
    Brendan
    Keymaster

    Hi Paulo,

    You can do this with the Child Records Loop snippet that’s available to you.

    Just select your Price field from your Table field on the Script Edit window, then double-click on the Child Records Loop snippet at the bottom-left.

    Tap Forms will write you a function which loops through the records of the Table field. You can then enhance it to pick out other fields too.

    Thanks!

    Brendan

    #40298
    Alejandro
    Participant

    Hi Sam! Thank You! I added your script to the Brendan’s script and I’ve got a new idea.

    Bu the way, I add this script that helps me to get the Fld_Ids:

    function Get_Flds() {

    var records = form.getFields();

    for (var index = 0, count = records.length; index < count; index++) {
    var theRec = records[index];
    var fld_id = theRec.getId();
    var name_id = form.getFieldWithId(fld_id).name;

    console.log(‘FieldName: ‘ + name_id + ‘\n’ + ‘ fld_ID: ‘ + fld_id + ‘\n\n’);

    }
    }

    Get_Flds();

    Paolo Sogono
    Participant

    Hi Everyone,

    I pretty new to TF5 and scripts. I hope someone can help my with my concern.

    I would like assistance in making a summary field that enumerates individual items from a Table Field.

    Form 1: Customers
    Fields: Name, Age

    Form 2: Products
    Fields: Name of product, description, instructions

    Form 3: Orders
    Fields: Customer(link from Form), Date of purchase, Product (Table Fields copy records from Products)

    E.g. John Doe, orders the ff items: a) A4, b) pencils, c) erasers on 2 April 2020.

    In the Orders Form these are displayed separately in rows in the Product Table (with corresponding price and description)

    I want to have a separate summary field in the Orders Form that will output the ff: “A4, pencils, erasers.”

    Example 2:
    Orders are
    1. A4, 500pcs, $10
    2. pencils, 1pc, $0.5
    3. A4, 500pcs, $10
    4. ballpen, 1pc, $1

    Output is “A4, pencil A4, ballpen.”

    I’m not sure if I was able to explain it clearly. Any help would be appreciated.

    #40295
    Sam Moffatt
    Participant

    Do you mean the customer name, phone and address details?

    I’d create a form script, inside the script editor you are going to be able to double click on the left to grab the Customers form (section header) and then double click on the fields you care about from that form (name, phone and address I guess).

    Next step is then double clicking on the notes field to get it’s current value. Then you’re going to want to append to it (presumably). To do that you’re going to want to combine the existing value with a new one.

    var notes = record.getFieldValue('fld-1234');
    record.setFieldValue('fld-1234', notes + "\n" + name + "; " + phone + "; " + address);
    form.saveAllChanges();
    

    Something like that will take the values from the name, phone and address field (assuming the variables ended up that way) and will add them to the existing notes field with a new line prepended. You need the form.saveAllChanges(); to make sure your changes are saved.

    #40292
    Sam Moffatt
    Participant

    This one isn’t too bad to get started on, when ever anyone has told me they want to learn programming my first question is what is the project or problem they want to solve. You’ve already got a small problem to solve which is a great place to start. I will suggest if possible maybe switching over from table to a link to form if you don’t have too much data because I know the link to form works but the table I haven’t used as much. Apart from having an extra form, it can behave more or less identically.

    Just to expand on the script, let me go line by line since it’s a relatively small script. This is a script field inside the new form and make sure you set up a Link to Form field from the existing form to your new form and also make sure the Link to Form field has ‘show inverse relationship’ ticked.

    var order = record.getFieldValue('fld-c3a6725d7d9446da92bbb880ffe90a9e');
    

    This first line is there to get a reference to the parent record (your current form right now). This is the piece I’m not so certain about how you get in the table field hence the suggestion to use a new form and Link to Form/Link from Form. In my case I have an Order form and then an Order Items form. For your situation you’ll need to change the fld-c3a6725d7d9446da92bbb880ffe90a9e to match the Link From Form field. To do that in the script editor for the script field, double click on the form header in the left panel.

    var order_items = order.getFieldValue('fld-9db0c7698499435ab6b18b7eb420e0ae');
    

    This is the Link To Form field and to get the value of this you’ll need to be in the equivalent of your Orders form (your current parent form). If you don’t have an existing script field to use, I generally create a new form script (third tab on the right panel), open up the editor and then get the ID I need. In this case you’re looking for the section heading with the name of your new form, in my case ‘Order Item’ and double click on that to get field ID to splice in above.

    In this situation, order_items returns a set of records linked to the parent record via the field. This essentially is all of the sibling records of the currently selected record.

    var line_number = record.getFieldValue('fld-f95b68d488cb4b058bbf3de84e1a7c3b');
    

    This is the new field in the new form that stores essentially your offsets. You can get this in the script editor by double clicking on the field name and it should insert this or a similar line with the correct field ID.

    if (!line_number)
    {
    

    This is a check to see if the line_number is not set on this record already. This just makes sure once it has a value set, it doesn’t overwrite it again.

    	record.setFieldValue('fld-f95b68d488cb4b058bbf3de84e1a7c3b', order_items.length);
    

    This line sets the value of the line_number field (notice the ID is the same) to the number of records currently linked to the parent (order_items.length). When this is working properly, each time a new record is created, the number of items will be incremented automatically. It’s not 100% perfect but it’s a good enough approximation that doesn’t require scanning all records to find the current maximum and set it to be higher than that.

    	console.log('Setting line number to ' + order_items.length);
    }
    

    I like lots of logging and I put in a log message just to see what is going on and we need to close out the if statement block hence the }.

    Hopefully this helps, a little more detail on what this script means and how to make it happen for yourself. Again I recommend switching over to a second form and a Link to Form field because I’m not sure how well this works with table fields.

    Good luck! Scripting in Tap Forms unlocks a large number of capabilities and gives you a large amount of power to customise your workflows.

    #40291
    Alejandro
    Participant

    Hi! I’m starting to use script in Tap Forms 5.
    Perhaps someone can help me with this. I think is easy but I’m stuck.

    Scenario: I have two forms that are related with the link to form option in a one to many way.

    Form Customers:
    Fields: Name, Phone, Address, Tickets (Link to Form)

    Form Tickets:
    Fields: Customers (Link From Form), Subject, Date, Resolve, Notes

    I want to run a script to add the value I see in Form(Tickets)->Customers to Form(Tickets)->Notes.

    Thank you!

    #40290
    iorbita
    Participant

    …the world of scripting and therefore programming is not yet part of my skills, I started to learn javascript recently, it will be a good exercise, thank you anyway ;)

    Lorenzo

    #40289

    In reply to: User calculation

    Brendan
    Keymaster

    Ah yes. That was just a variable scope issue for you.

    If you had just moved the var definitions above function Nieuw_Script(), it would have worked too.

    #40288

    In reply to: User calculation

    I took the script out of the automatic generated function (Nieuw_Script) and now it works fine!


    // *** Bereken het excl bedrag van het gegeven veld ***

    var output = function berekenExBtw(continued) {

    var exBtw = 0;
    var btw = 0;
    var exBedrag_ID = form.getFieldNamed('Bedrag 1').getId();
    var BTW_TYPE_ID = form.getFieldNamed('btwType').getId();
    var btwAmount = record.getFieldValue(BTW_TYPE_ID);

    if (continued == true) {
    if (inclusief) {

    if (btwAmount == '9') {btw = 9};
    if (btwAmount == '21') {btw = 21};

    exBtw = (inclusief/(btw+100))*100;

    // console.log("Het incl. bedrag is: " + inclusief + " Het excl. bedrag is: " + exBtw);

    record.setFieldValue(exBedrag_ID, exBtw);

    form.saveAllChanges();

    }

    } else {
    console.log("Cancel button pressed.");
    }
    }

    var inclusief = 0;

    let prompter = Prompter.new();
    prompter.cancelButtonTitle = 'Afbreken';
    prompter.continueButtonTitle = 'Berekenen';
    prompter.addParameter('Inclusief bedrag: ', 'inclusief')
    .show('Bereken Exclusief BTW', output);

    #40274
    Sam Moffatt
    Participant

    I found the post that I was thinking of but it was a generic counter implementation.

    It’s a little more involved, here’s a simpler script I use with a link to form use case.

    var order = record.getFieldValue('fld-c3a6725d7d9446da92bbb880ffe90a9e');
    var order_items = order.getFieldValue('fld-9db0c7698499435ab6b18b7eb420e0ae');
    var line_number = record.getFieldValue('fld-f95b68d488cb4b058bbf3de84e1a7c3b');
    
    if (!line_number)
    {
    	record.setFieldValue('fld-f95b68d488cb4b058bbf3de84e1a7c3b', order_items.length);
    	console.log('Setting line number to ' + order_items.length);
    }

    This is a little tricky, order is the parent record (the Link from Form field) , order_items are all of the children of the parent (a Link to Form field in the parent reecord) and then line_number is the line number. I could probably change it to use the max function that was added but for the most part this works for me. As Brendan suggested you could add in a multiplier (e.g. order_items.length * 10) to give yourself some space around the numbers.

    The order and line_number field equivalents will be accessible via the script editor directly and for order_items I opened up the order form and got it’s field ID from there.

    You should be able to modify it to work with a table field as well though I’ve personally never done much with table fields and scripts. There is something special about the scripting environment inside of a table though a quick glance at the documentation doesn’t reveal it. Perhaps Brendan can chime in on this one.

    #40270

    In reply to: User calculation

    I tried the example script ‘Prompter class’ from the documentation,
    but I get ‘undefined’ for every variable….

    Is this a bug or do I something wrong?

    Thanks, Andreas.

    Attachments:
    You must be logged in to view attached files.
    #40268

    In reply to: User calculation

    Brendan
    Keymaster

    Yes, you could certainly do that with a Form Script.

    You would use the functions: record.getFieldValue(field_id) to get the value from your Total field, then perform your calculation on that value, then call record.setFieldValue(vat_id) to set the value on your VAT field.

    Then call form.saveAllChanges(); to save the results.

    #40264

    In reply to: User calculation

    Yes, I could indeed use the calculation field, but in most cases I don’t need this calculation.
    I now have an invoice with the input of services that are added together and then calculated with VAT to the total. Only in very rare cases do I have to calculate the other way round, so I have the total and have to calculate the amount without VAT.
    Is this then possible to do it with the help of a script?

    Tanks!

    Attachments:
    You must be logged in to view attached files.
    #40258
    Sam Moffatt
    Participant

    I have a script I use that I think I’ve posted elsewhere for the ordering of child records, that means you can edit the ordering field relatively straightforward. It’s a reply to a similar sort of thread. I’ll reply here if I find it again.

    #40252
    Victor Warner
    Participant

    Thank you, but a brief look at the link does not provide how, what and where I add the relevant regular expression. The code provided in the linked page does not seem to relate at all (for someone who does not know JavaScript) to the examples you have provided.

    Can you, Brendan, or someone else provide how it is possible to search for any text appearing in a field (as a wildcard, whether with regular expression or without) and replace it with something?

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