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 - 301 through 315 (of 2,989 total)
  • Author
    Search Results
  • #51198
    Daniel Leu
    Participant

    Do you have some type of criteria to select these records? Can you create a saved search for them? Or is it for all records?

    Do add them to the list, I think the only way is using a script. Here’s an example of what I’m using:

    var prompterVar;
    
    function callbackSetTag() {
       const name_id = 'fld-xxx';
       const tags_id = 'fld-xxx';
       // get records from a saved search
       let recs = form.getSearchNamed('Selected').getRecords();
       // // use all records
       // let myRecords = form.getRecords();
       console.log('Found ' + recs.length + ' records');
       for (rec of recs){
          console.log("Processing " + rec.getFieldValue(name_id))
          var tags = new Array();
          // load initial values
          var tag = rec.getFieldValue(tags_id);
          // create an array of tags
          if (tag) {
             tags = tag.split(",");
          }
          // add new tag
          if (prompterVar){
             tags.push(prompterVar);
          }
          // save new tags
          rec.setFieldValue(tags_id, tags.toString());
          console.log("Setting tags: " + tags.toString());
       }
       document.saveAllChanges();
    };
    function setTag(){
       let prompter = Prompter.new();
       prompter.addParameter('Tag', 'prompterVar', 'text')
       .show('Add Tag to current record', callbackSetTag);
    }
    setTag();
    You will need to update the name_id and tag_id constants. name_id is used in the console log to provide some infos on which record the routine is running. tag_id is the field where you collect your tags. In your case, that would be the Mailings field.
    Next, you have to decide if this works on a saved search or on all records. My saved search is called Selected. Either you update this, or comment this line and uncomment the next block to perform the tagging on all fields.
    When you run the script, you get a prompter where you enter the new tag. Note, the tag may not contain commas!
    Hoffentlich hilft das. Viel Spass und Erfolg!

    Cheers, Daniel

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

    #51196
    Anonymous
    Inactive

    Hi,

    is there a way to add text to a text field of multiple records? In My example I am sending out mailings and want to note that in those records which will get the mailing.

    The field is set up as a text field and has the selection thing, where I can choose from the list.  The first two mailings I just filld the field by dragging the yellow dot in a spreadsheet-style.

    Ticking off over one thousand records individually is quite time consuming.

    I thought I could select those records and then select from the list to add it. But that’s not possible.

    My attempt to do a script failed miserably, my brain seems to work the other way around.

    Any Ideas how this could be done? Or has anyone already done a script fot this kind of operation?

    Thanks

    Stephan

     

     

    #51194
    Daniel Leu
    Participant

    You can do this with a field script that formats your field whenever you change it. You need to update the text_id variable to point to your text field. I would recommend to hide the field script in order not to clutter the default view.

    
    function capitalizeFirstLetter(string) {
    
        return string.charAt(0).toUpperCase() + string.slice(1);
    }
    function Text_Formatter() {
       var text_id = 'fld-b6f734989f3742c8b6d1ad301eefea32';
       let text = record.getFieldValue(text_id);
       text = capitalizeFirstLetter(text.toLowerCase());
       record.setFieldValue(text_id, text, false);
       document.saveAllChanges();
       return text;
    }
    Text_Formatter();

    I noticed that the script wasn’t triggered when I first created it. Closing and reopening the TapForms document fixed it!

     

     

    Cheers, Daniel

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

    #51181
    John Hamill
    Participant

    Hello,

    I cannot see a method for achieving the enclosed (screenshot) search which necessitates a combination of ‘AND’ and ‘OR’ logic, a compound logic statement. [The second screenshot is included for information only and displays the ‘Rating’ field that I wish to add].

    I can go to Javascript. But when using Javascript, is it possible to replicate a “saved search” with all of its functionality (browsing through records etc) without major coding ie. creating a new table and populating that new table with the search results?

    Or perhaps, I am missing something simple?

    Thanks for any assistance.

    • This topic was modified 1 year, 3 months ago by John Hamill. Reason: Original did not attach images
    Attachments:
    You must be logged in to view attached files.
    #51156
    JScottA
    Participant

    Maybe this response from the ChatGPT Tap Forms 5 Assistant can help you. It is a bit long, but that is how this custom GPT works. I hope it helps:

    It seems the user is facing an issue with JavaScript’s .match() method and handling null values. Here’s what I can suggest based on their code.

    ### Issues with the Provided Script:
    1. **Incorrect Regex Format**: The regular expression is defined as a string ("/5bq/"). In JavaScript, regular expressions should not be placed inside quotes like that unless explicitly instantiated using the RegExp constructor. Alternatively, regular expressions can be directly written using the / delimiter without the need for quotes.

    2. **Null Handling**: The user is correct that .match() returns an array when a match is found and null when no match is found. The current handling of null is fine with the if (found === null) check, but fixing the regex issue should resolve their problem.

    ### Suggested Fix:
    Here’s a corrected version of their script:

    `javascript
    function Test_Script() {
    const regex = /5bq/; // Corrected regex format
    var tstr = “ytube5bq891”;
    const found = tstr.match(regex);

    if (found === null) {
    console.log(‘No match’);
    } else {
    console.log(‘Match found’);
    }
    }

    Test_Script();
    `

    ### Explanation:
    – **Regex without quotes**: The regular expression /5bq/ is now correctly formatted as a regex object, not a string. JavaScript will treat this as a valid regex pattern and search accordingly.
    – **Null Check**: The rest of the code remains the same because the handling of null and matches with if (found === null) is already correct.

    ### Additional Notes:
    – If you want to dynamically create a regex (e.g., from user input), you would use the RegExp constructor like this:
    `javascript
    const regex = new RegExp(‘5bq’);
    `

    This should fix the issue and allow the script to properly check for matches.

    For further Tap Forms scripting assistance, you can refer to [Tap Forms Scripting 101](https://www.cattail.nu/tap_forms/tap_forms_scripting_101/index.html). You can also check the scripting section in the Tap Forms documentation around page 53 [oai_citation:1,1328_16794_en_1538683502.pdf](file-service://file-15C3MsaZPdU2JvfF2hiej31w).

    You can check more about Tap Forms here: [Tap Forms Assistant](https://chatgpt.com/g/g-aGOEAlajR-tap-forms-5-assistant).

    #51155
    John Hamill
    Participant

    Hello Daniel,

    I was a bit presumptuous above. I am still having a problem with your script. I have simplified the problem – it may be down to the Javascript ‘match’ function returning an array (true), otherwise returning null, null having its own “difficulties” in Javascript. I have excluded the field id for the present to simplify it. I am still unable to get it working however. Here is my test script:

    function Test_Script() {
    const regex = “/5bq/”;
    var tstr = “ytube5bq891”;
    const found = tstr.match(regex);
    if (found === null)
    console.log(‘No match’);
    else
    console.log(‘Match found’);
    }
    Test_Script();
    #51146
    Daniel Leu
    Participant

    If I run into issues with the search, I tend to write a field script:

    
    
    function Match_T259S() {
    var field_id = 'fld-xxxx';
    var field = record.getFieldValue(field_id);
    const regex = /\&t=259s/g;
    const found = field.match(regex);
    return found ? 1: 0;
    }
    Match_T259S();
    Then I create a saved search on that field. You need to adjust the field_id for the field that contains your URL text. The return value of this field script is integer.

    Cheers, Daniel

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

    #51131

    In reply to: Movie Library Template

    Anonymous
    Inactive

    I did add the API values to the script. And I can see the data echoed back in the console log. I’ve tried a few different movies. When I get some time, I’ll try to debug, but thought I’d check to see if an update was already done. thanks for replying.

    Is the update faulty? I just downloaded it.

    #51101
    Kyla Lemon
    Participant

    Hi All –  I am running a Quilt Show using Tap Forms!  I have done so much already (actually very easy to use), but I need to figure out one more thing.  I have 200 records, one record per quilt entry.  I have already made layouts for display cards, layout cards, and spreadsheets for other committees.  But I need to group/link records by “quilter”.  I need a layout that will list all of the quilts entered by one individual.  We use this layout to check-in and check-out quilts.  Some people enter 1 quilt, others have 5 or more.  Not sure if this requires a script or linking records?  Any advice would help, as I am running out of time, the show starts on 9/19.  Thank you! – Kyla

    #51095
    JScottA
    Participant

    Thank you! I do not want an online version of TF5! An online database defeats the Apple Intelligence on-device approach! It wouldn’t be bad to adopt some of the UX approaches to making TF5 more approachable for average users, but I agree with your decision not to build an online version!

    I’m hoping for a really well-integrated local database that I (and others, of course) can use to quickly generate tables and more for use with the on-device AI and with Apple’s on-device automation! That is Shortcuts and AppleScript, of course.

    I’ve given examples in other posts here, but I’ll give another possible feature that I think would be useful to many people. Using App Intents with TF5 (as a backend) to use with Shortcuts and AI to optimize data for AI usage. Of course, TF5 won’t be a vector database, but it would still be much better than trying to work with disparate and possibly large spreadsheets.

    #51085
    JScottA
    Participant

    I’ve been watching your blog for any news, but I realize you’ve probably been very busy working on TF5. Are there any updates on Apple Intelligence, App Intents, Shortcuts, or AppleScript that we might look forward to, in the near future? For example, are there any updates on us being able to use Tap Forms like we currently use AirTable is its ilk online? I would really prefer a local solution.

    #51084
    Brendan
    Keymaster

    Oh wow, that’s a lot of work you did there.

    Would it maybe be easier to write the Apple Script to just trigger the menu command within Tap Forms to recalculate the formulas?

    But also, you have to trigger your script yourself anyway, or do you have that on a timer or something?

    #51081
    JScottA
    Participant

    FYI…I was able to use a combination of Tap Forms 5, ChatGPT app, Apple Shortcuts, and AppleScript to analyze the content (in this case a blog post) and create desired hashtags based on rules that I set in the GPT.

    Hopefully, TF5 will get an ability to use LLM models internally and we can skip a lot of the external scripting some day soon!

    Note* I did cheat and use the TF5 Assistant to work through the details on the scripting and TF5 connections.

    #51077
    David Oxtoby
    Participant

    update, somethings should be left alone…. but you know what it is, down the rabbit hole. anyway I have worked out how to do what I needed, which is update a calculated field outside of tapforms, here we go if anyone else wants to go down this road.

    my situation. i have a days left until a given date calculated field (i.e. days until insurance due or MOT due), that I didn’t want to have to trigger a Formula Recalculation through pressing the button in TF manually, but wanted this to happen daily somehow. (the rest of the record in TF stays fairly static so nothing gets changed to often to force a refresh/update of the calculated fields).

    my solution was to find a way to make the change to the calculated field value via CouchDb instead, which works ok.

    the steps in summary are.

    1. identify the id of fields in TF (for me:

    fld-555b6e75e1f0483ead9ca9cc2c122569 is my calculated field, i.e. days left to go

    fld-c09f1fbc054647859d811dfdd228abea is my date field I’m using to do the above

    2. create a view document in CouchDB to find all documents (records) that contain that field id

    3. create an update function/document in CouchDB to update the designated field value with the new value you want

    4. create a script (for me AppleScript) to execute daily, to make those changes in CouchDb.

     

    if you’re still reading, here’s some more details.

    my search document in couchdb:

    {
    “_id”: “_design/search_view”,
    “_rev”: “20-301796ba60a199c905367bf1fadefe83”,
    “views”: {
    “search_view”: {
    “map”: “function(doc) {\n function searchValue(value) {\n if (typeof value === ‘object’ && value !== null) {\n for (var key in value) {\n if (value.hasOwnProperty(key)) {\n if (key === \”fld-555b6e75e1f0483ead9ca9cc2c122569\” || searchValue(value[key])) {\n return true;\n }\n }\n }\n } else if (value === \”fld-555b6e75e1f0483ead9ca9cc2c122569\”) {\n return true;\n }\n return false;\n }\n\n if (searchValue(doc)) {\n emit(doc._id, null);\n }\n}”
    }
    },
    “language”: “javascript”
    }

     

    create the update handler document in couchdb

    {
    “_id”: “_design/updates”,
    “updates”: {
    “recalculateDaysDiff”: “function(doc, req) {\
    if (doc.values && doc.values[‘fld-c09f1fbc054647859d811dfdd228abea’] && doc.values[‘fld-c09f1fbc054647859d811dfdd228abea’].date) {\
    var targetDate = new Date(doc.values[‘fld-c09f1fbc054647859d811dfdd228abea’].date);\
    var currentDate = new Date();\
    var timeDiff = targetDate – currentDate;\
    var daysDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));\
    doc.values[‘fld-555b6e75e1f0483ead9ca9cc2c122569’] = daysDiff;\
    }\
    return [doc, ‘Updated the days difference’];\
    }”
    }
    }

     

    now create the AppleScript to use both the view and update documents in couchdb

    set dbName to “your-database-name”
    set viewName to “_design/search_view/_view/search_view”
    set updateHandler to “_design/updates/_update/recalculateDaysDiff”

    set userName to “your-username”
    set userPassword to “your-password”
    set baseUrl to “http://127.0.0.1:5984/”
    set jqPath to “/opt/homebrew/bin/jq” — Use the full path to jq, tool to help split records returned

    — Create the URL to query the view for document IDs starting with “rec”
    set queryUrl to baseUrl & dbName & “/” & viewName & “?startkey=%22rec%22&endkey=%22rec%5Cufff0%22”

    — Fetch the document IDs using the full path to jq
    set docIds to do shell script “curl -s -u ” & userName & “:” & userPassword & ” \”” & queryUrl & “\” | ” & jqPath & ” -r ‘.rows[].id'”

    — Convert the result to a list of IDs
    set docIdList to paragraphs of docIds

    — Loop through each ID and trigger the update handler
    repeat with docId in docIdList
    set updateUrl to baseUrl & dbName & “/” & updateHandler & “/” & docId
    do shell script “curl -X PUT -u ” & userName & “:” & userPassword & ” \”” & updateUrl & “\””
    end repeat

    — Notify the user that the script has finished successfully
    display notification “Document updates have been processed successfully.” with title “Script Completed”

     

    when this runs it updates all the records in couchdb with my newly calculated field, and this then triggers the sync with TF and I see the updated values appear without me need to manually click any forms of Recalculate Formula’s button.

    obviously this is for sharing and learning together, but please use with care if helpful.

    • This reply was modified 1 year, 4 months ago by David Oxtoby.
    • This reply was modified 1 year, 4 months ago by David Oxtoby.
    #51075
    David Oxtoby
    Participant

    Thx, my triggering via a ‘touch’ of CouchDb worked via AppleScript at a scheduled time, in that it forced TapForms to ‘refresh’, but it didn’t trigger a Formula Recalculation… more work needed.

Viewing 15 results - 301 through 315 (of 2,989 total)