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 - 751 through 765 (of 2,989 total)
  • Author
    Search Results
  • #48329
    Lane Robinson
    Participant

    OK. I’m committing to using javascript for this. Just when I think I’m out they pull me back in!

    When using a script, do I do it something like this?

    select a record from my Ad Rates form where Ad Size = the value of Ad Size on my Orders form? And then get the value of the Ad Rates field on the selected record?

    reading the API right now.

    #48328
    Lane Robinson
    Participant

    OK. So a multi field fill instead of a lookup. A table is basically like a form, but a sub form of its parent form. It’s always going to be a table with a single row in this case. And I guess I can’t sort a layout by the ad size field in that table, which I need.

    So I’m trying to pull data up to the main form using a calculation. I can see how I can do a total of the ad price from the table onto the main form. But I can’t seem to get the ad size out. I’ve tried using a concat. All it seems to allow is a count, which is auto inserted with the field when I move the field into the Formula space. Trying to change this to a concat isn’t understood.

    It’s not ideal that I would use a calculation for this anyway, as I may need to override or otherwise enter a custom value. I can live with it if it has to be a calculation. Would so much prefer an autofill I can change.

    Would a script allow me to manually overwrite a value it returns? I wouldn’t think so. Perhaps I could add an ‘override price’ field the script would read from and return. Awkward looking, but would do the job.

    #48327
    Brendan
    Keymaster

    The nice thing about JavaScript in Tap Forms is that you don’t have to worry about all of that DOM junk you have to deal with when writing JavaScript code for a web browser.

    Here’s a simple example:

    function countPhotos() {
       var photo_id = 'fld-....';
       var photos = record.getFieldValue(photo_id);
       if (photos != undefined) {
          return photos.length;
       } else {
          return 0;
       }
    }
    
    countPhotos();

    Not too bad if you’ve got some sort of programming background. And even if you don’t there’s plenty of examples on this site you can learn from.

    #48325
    Brendan
    Keymaster

    The Table field is a good use for this sort of thing.

    Take a look at the Invoices sample template:

    https://www.dropbox.com/s/6rkk6413cbv3aj1/Invoices.tapforms.zip?dl=1

    In there you’ll see an Orders form that has an Order Items Table field in it. The Order Items field is connected to the Products form. When you click the checkmark button to choose a record from the Products form, Tap Forms will copy multiple fields from the Products form into the Order Items Table field, including the product name and price.

    Another way to do it is to use a Script field that fetches the value you want from another form. But that’s a bit more complicated to achieve.

    #48323
    JB Be
    Participant

    Thanks, Patrick, for taking this up. I admit that scripting is to hard for me (although I gave it a try). Getting a menu command as you described would save my investment in TF… :-|

    #48313

    Topic: Date comparison

    in forum Script Talk
    Ian Wheeler
    Participant

    Hi Folks,

    I am trying to check via a script whether a Date field contains a date that is earlier than today. If it is then I want to delete the record. Ideally this would be a manually run script. I am very new to TF (and loving it, and am in the process of migrating over from Filemaker) and Javascript. Below is the script that I have which just doesn’t work. I suspect it is my Date comparison element that is the problem as the Console.Log isn’t detecting any errors, but I don’t know how to fix it. Any help would be greatly appreciated

    function Delete_Expired_Docs() {
    
    	var records = form.getRecords();
    var field_id = 'fld-46f16c00d13344e79478a8b629022ee7';
    	
    for (var index = 0, count = records.length; index < count; index++){
        var aRecord = records[index];
        var field_value = aRecord.getFieldValue(field_id);
        if (field_value < Date()) {
            form.deleteRecord(aRecord);
        }
    }
    
    form.saveAllChanges();
    
    console.log(field_value);
    console.log(count);
    console.log(Date());
    
    }
    
    Delete_Expired_Docs();
    • This topic was modified 3 years, 1 month ago by Brendan.
    • This topic was modified 3 years, 1 month ago by Brendan. Reason: formatted code
    #48301
    Lane Robinson
    Participant

    Thanks for those comments Chris.

    So I’m a used to be programmer who hates javascript. I’ve dipped into it here and there. And while I might end up needing to use it, I am very deeply hoping I don’t need to! But at least it’s not AppleScript, which might be Dante’s ninth circle. :P

    #48300
    Chris Ju
    Participant

    I can definitely confirm that you can map really complex business processes with TapForms. With lists and Java Script support (see Java Script documentation on the homepage) you can really automate nearly everything…

    #48284
    Daniel Leu
    Participant

    I got it working with following code, but using while() is not really elegant and just consumes CPU cycles

    function sleep(delay) {
        var start = new Date().getTime();
        while (new Date().getTime() < start + delay);
    }
    
    function Add_To_Clipboard() {
    
    	Utils.copyTextToClipboard("one");
    	sleep(200);
    	Utils.copyTextToClipboard("two");
    	sleep(200);
    	Utils.copyTextToClipboard("three");
    	sleep(200);
    	Utils.copyTextToClipboard("four");
    }
    
    Add_To_Clipboard();

    When I use sleep(100), not all copies are recored. So the delay might depend on the performance of the target computer.

    Re: Javascript, there is setTimeout(), but that’s part of DOM and not ECMAScript. Feature request: add Utils.setTimeout() and maybe Utils.clearTimeout() too. Then I could do

    function sleep(ms) {
      return new Promise(resolve => setTimeout(resolve, ms));
    }
    
    for (let i = 0; i < 5; i ++) {
      if (i === 3)
        await sleep(2000);
      console.log(i);
    }
    • This reply was modified 3 years, 2 months ago by Daniel Leu.

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #48283
    Brendan
    Keymaster

    I just put a sleep(2) or something like that in my Objective-C code just for testing purposes. I took it out already. Maybe there’s something similar with JavaScript.

    #48278
    Chris Ju
    Participant

    Did you put an artificial delay in java script or in the code of TF?

    For the first case, it would be great if you could share the script, because my delay doesn’t work.

    #48261
    Brendan
    Keymaster

    Hi Jean-Christophe,

    I suspect the error on iOS might be because the field being referenced doesn’t exist perhaps? I’m not sure without having access to your script and form.

    Would you be able to email me a copy of your form template so I can look into it?

    You may also need to check to make sure you have data in the fields before you call the setters too.

    #48260
    Daniel Leu
    Participant

    Yeah, looks like a bug to me.

    I just run a little script and indeed, only ‘four’ appears in the clipboard history (CopyClip):

    function Add_To_Clipboard() {
    	Utils.copyTextToClipboard("one");
    	Utils.copyTextToClipboard("two");
    	Utils.copyTextToClipboard("three");
    	Utils.copyTextToClipboard("four");
    }
    
    Add_To_Clipboard();

    A workaround would be to put all the variables into a JSON formatted string and copy that to the clipboard.

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #48256
    Chris Ju
    Participant

    Hi,

    i’m trying to copy some variables to clipboard. However, I would like these to be copied separately to the clipboard. I define the variables (var1, …, var9), but when I use the Utils.copyTextToClipboard(var1) … Utils.copyTextToClipboard(var9) command, only the last variable is copied to the clipboard. I’m using Launchbar-App, with which i could see a history of the clipboard.

    I already used a delay script, between the variables/copy-cammand, but that doesn’t helped.

    Does anyone has an idea?

    Thanks
    Chris

    #48255
    Brendan
    Keymaster

    The script function won’t open a form. Go to the record details screen and tap on the action menu and select Copy Record Link. That’ll give you the URL to view that record.

Viewing 15 results - 751 through 765 (of 2,989 total)