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,426 through 1,440 (of 2,952 total)
  • Author
    Search Results
  • #43713
    Eddy
    Participant

    Hi Sam!

    Thanks a lot.

    But I am afraid, this is not really, what I need and search for.

    Actually I need a way, that fills in the geocoordinates automatically according to the address-date I wrote in by my script.

    Hope, now I express myself better. Sorry for any confusion.

    Regards, EDDY

    #43710
    Daniel Leu
    Participant

    I’ve never used the location field, so I’m not familiar with it.

    But in your script, you are missing a document.saveAllChanges(); after setting the location field. If you click on Refresh records list, all records should be updated and the location saved.

    Cheers, Daniel

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

    #43708
    Eddy
    Participant

    Hi Folks!

    QUESTION:

    How can I force the location field to look automatically for the geocoordinates without opening it manually?

    CASE

    We need a to have an overview of our clients on map view. But it would be to much work to fill the location field manually. So, I have a little script, that fills the location field based on the data in the adress fields.

    function FILLING_locationfield() {
    
    var ADR_street = record.getFieldValue('fld-a2…');
    var ADR_postalcode = record.getFieldValue('fld-b7…');
    var ADR_city = record.getFieldValue('fld-e6…');
    var ADR_country = record.getFieldValue('fld-b9…');
    
    var TARGETFIELD_locationfield_id = 'fld-01…';
    
    var ADDRESSDATA_for_locationfield =	
    ADR_street + ", " + ADR_postalcode + " " + ADR_city + ", " + ADR_country ;
    
    record.setFieldValue(TARGETFIELD_locationfield_id, ADDRESSDATA_for_locationfield);
    }
    function FILLING_locationfield();

    The problem is: This is filling the location field properly with the adress data. But in order that the location field is getting the fitting geocoordinates, I have to click on each adressfield manually and then to click on the save button.

    So: How can I force the location field to look automatically for the geocoordinates without opening it manually?

    Thanks in advance for any help.

    Stay healthy, EDDY

    #43703
    Sam Moffatt
    Participant

    Correct, the standard built in Javascript engine works within the scripts.

    If you check out my repo there is a match example and a replace example (also includes a sample of creating a RegExp object as well if you look up a few lines).

    #43702
    Brendan
    Keymaster

    I imagine you can just use the regular JavaScript regular expression support:

    https://www.w3schools.com/js/js_regexp.asp

    But I haven’t tested it myself.

    #43699
    Victor Warner
    Participant

    I have a text field. It contains names (usually two or three words).

    Is it possible to extract only the first word in a script field in way using regular expressions? (eg ^(\S+) (.*)$ or ^(.+?) (.*)$).

    Brendan
    Keymaster

    I’m glad you were able to figure it out.

    The trigger mechanism is that if you have a call to getFieldValue(some_field_id) in a Script field, Tap Forms will execute the script whenever the value of some_field_id is changed.

    Sam Moffatt
    Participant

    I’m seeing the same thing, the results just aren’t showing up in the table. Here’s my test script:

    "Hello, World";
    

    Works fine in the script editor but never shows up in the table. I do believe we’ve found ourselves a bug!

    Quick idea: have the script editor show the parent fields like a link to form style relation but instead automatically inserting the record.parentRecord.getFieldValue as the code completion.

    Sam Moffatt
    Participant

    You want a field controlled by the script because if you do a recalculation, it’ll re-run all of the scripts in a record. If you recalc an entire form then it’ll check it for everything. If you’re checking if the bar code field is set to a value then you will hit the API again. That will mean that you’ll likely exceed the limit again and you’ll be waiting a day for things to be available again.

    For something like this you don’t need a full mock server, just copy and paste to a text file, point Apache at it (plenty of guides on how to do that out there) and then instead of pointing Tap Forms at the real source, you work against the saved file. More complex APIs a little harder but unless there is something truly dynamic in each request, you can get a sample page and use that to develop against.

    In any case glad to hear it’s working for you!

    Ray Robillard
    Participant

    Found the answer to my question. When the Bar Code field gets a value, the script is executed automaticaly.

    And now, it’s working fine.

    Daniel Leu
    Participant

    record.parentRecord: Ah, another hidden feature. Cool! Could this be documented, and the editor isn’t aware of it either. Thanks!

    But there is an issue: It looks like the return value of a field script isn’t propagated to the table script field. Here is my test code:

    function ScaledValue() {
    	const quantity_id = 'fld-xxx'
    	let quantity = record.parentRecord.getFieldValue(quantity_id)
    	return quantity
    
    }
    
    ScaledValue()

    Cheers, Daniel

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

    Brendan
    Keymaster

    Also, on a script you can get record.parentRecord to get the parent record for that child record. It will give you back a record object the same as record which you can then call getFieldValue() on.

    Ray Robillard
    Participant

    The model I use when interacting with remote services that my script field updates another field and only runs if that other field doesn’t have a value.

    In my case, I have a bar_code field which is empty at first, but gets populated after I use the camera to scan the UPC on the product. I want the search to run when that field is populated. How do I proceed ?

    The other pattern I do is to cache the responses locally and copy the response I get back and put it on a local web server (MacOS comes with Apache built in).

    This looks like a mock server and this is way over my league :) (last time I programmed something was probably for with Visual Basic 3 under Windows 3.1.. haha !)

    Sam Moffatt
    Participant

    The model I use when interacting with remote services that my script field updates another field and only runs if that other field doesn’t have a value. If something is wrong, I can empty out that field and it’ll repopulate it but it means that once that field is set, the script doesn’t poll the remote service. With 800 records and on save you’ll have blown through that quota the first time you saved and they’ll likely hold you to the 24 hour window. The main place I use this model is with a FOREX field for converting remote currency values to local currency (generally an approximation but usually close enough).

    The other pattern I do is to cache the responses locally and copy the response I get back and put it on a local web server (MacOS comes with Apache built in). Then I point my script to it and iterate on it until it behaves the way I want. In this situation that would have meant a request to get the sample response back and then once I’m done with development, I switch back to the real one. I also have some caching proxy for some endpoints to be able to capture API responses and also to quickly return identical requests.

    Ray Robillard
    Participant

    I tried again this morning, but I’m still getting the same error message. I’ll try later this afternoon, after a full 24 hours period. But you were right, the code was set to update records on save. Having 800 titles in my database, that could explain why I received the error message.

    That said, I still need help on how to implement this. Do I create a field script and put the code in and another field, bar_code, that I use to input the code (or use the camera on the iPhone)… ? So the script will be triggered when text is input in the bar_code field ?

Viewing 15 results - 1,426 through 1,440 (of 2,952 total)