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 - 331 through 345 (of 3,016 total)
  • Author
    Search Results
  • #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, 5 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, 6 months ago by David Oxtoby.
    • This reply was modified 1 year, 6 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.

    #51074
    JScottA
    Participant

    Using your initial query and script problem, I ran it through the TF5 assistant to see if it was helpful:

    The script you provided is almost correct but seems to be missing a couple of critical aspects, particularly regarding how Tap Forms triggers scripts and how it handles table fields.

    In Tap Forms, scripts are generally not automatically triggered by field changes such as checking a checkbox. Instead, scripts are usually run manually or via a button field or script field that the user has to click to execute.

    Here’s a refined version of your script with some improvements:

    `javascript
    function deleteCheckedRows() {
    var tableFieldID = ‘fld-e6d2b5eaf2fb4e78b708ff36d05f31a5’;
    var checkmarkFieldID = ‘fld-475a8bbcba634befbca61e39a61fef8c’;

    // Get the rows in the table field
    var tableRows = record.getFieldValue(tableFieldID);

    // Array to hold the rows that should remain
    var rowsToKeep = [];

    // Loop through each row in the table field
    for (var i = 0; i < tableRows.length; i++) {
    var row = tableRows;

    // Check if the checkmark field is selected (true)
    if (!row.getFieldValue(checkmarkFieldID)) {
    // If not selected, keep this row
    rowsToKeep.push(row);
    }
    }

    // Set the filtered rows back to the table field
    record.setFieldValue(tableFieldID, rowsToKeep);

    // Save changes
    document.saveAllChanges();

    // Optional: Provide feedback
    Utils.alertWithMessage(“Checked rows deleted”, “All checked rows have been deleted.”, “info”);
    }

    // Run the script
    deleteCheckedRows();
    `

    ### Key Points:
    1. **Manual Execution:** As per Tap Forms’ typical functionality, you’ll need to trigger this script manually, possibly by adding a script field or button field to run it.

    2. **Correcting Array Access:** In the loop, var row = tableRows; was adjusted to properly access each row in the table.

    3. **Triggering:** If you’re expecting this to run automatically when a checkbox is ticked, Tap Forms does not support that natively. You may need to manually run the script after checking boxes, unless you incorporate it into a workflow where a button click triggers the script.

    ### Execution:
    You might need to manually run the script by selecting it from the Scripts section or by creating a button in your form that users can press after they have checked off the tasks they want to delete.

    For more detailed scripting references, you may need to refer to the Tap Forms scripting documentation or related resources [oai_citation:1,1328_16794_en_1538683502.pdf](file-service://file-15C3MsaZPdU2JvfF2hiej31w).

    #51073
    JScottA
    Participant

    Skimming through the thread, you may have already addressed your initial question yourself. However, I thought I might share what the TF5 Assistant gave me on the initial trigger question…maybe that will help you in the future:

    Tap Forms does not explicitly mention an “on-form-load trigger event” like those found in some other database or development environments. However, you can achieve similar functionality through the use of scripts. In Tap Forms, you can write JavaScript that can be manually triggered or set up to run under specific conditions, but it lacks the automated “on-load” trigger directly tied to the form’s loading.

    For more detailed scripting capabilities, you may need to manually execute scripts when the form loads or tie the script execution to a specific user action within the form. This can be done using the JavaScript API that Tap Forms provides.

    If you need further customization or a workaround, I recommend checking out the JavaScript API section of the Tap Forms documentation starting on page 53, which outlines how you can implement custom scripts [oai_citation:1,1328_16794_en_1538683502.pdf](file-service://file-15C3MsaZPdU2JvfF2hiej31w).

    #51072
    David Oxtoby
    Participant

    for anyone following, I fixed my killed field in couchdb, so it now appears back in TapForms; here is the AppleScript for anyone following; obviously, you’ll need to tweak your own values into the curl command to reflect your TapForm values etc.

    — Define CouchDB URL and credentials

    set couchdbURL tohttp://192.168.1.240:5984/db-1a619b6d486c466c9fc32a1b4a494f00&#8221; — Replace with your CouchDB database URL

    set couchdbUser to “admin” — Replace with your CouchDB username

    set couchdbPassword to “antony” — Replace with your CouchDB password

     

    — Define the document ID and the fields to be updated

    set documentID to “fld-0f69d93fa3bd48c99df27375911e2040” — Replace with your document ID

    set fieldName to “name” — The field name to update

    set fieldValue to “Test” — The new value for the field

     

    — Step 1: Fetch the current document to get the _rev value

    set fetchURL to couchdbURL & “/” & documentID

    set fetchCommand to “curl -u ” & couchdbUser & “:” & couchdbPassword & ” ” & fetchURL

     

    — Debug: Display fetch command

    — display dialog “Fetch Command: ” & fetchCommand

     

    set documentJSON to do shell script fetchCommand

     

    — Debug: Display raw JSON response

    — display dialog “Document JSON: ” & documentJSON

     

    — Extract the _rev value from the document JSON using Python for robust JSON parsing

    set pythonCommand to “python3 -c ‘import json, sys; doc = json.load(sys.stdin); print(doc[\”_rev\”])'”

    set revResult to do shell script “echo ” & quoted form of documentJSON & ” | ” & pythonCommand

     

    — Debug: Display extracted _rev value

    — display dialog “Document Revision (_rev): ” & revResult

     

    — Step 2: Create the JSON payload for the update, including additional fields

    set jsonPayload to “{\”_id\”:\”” & documentID & “\”, \”_rev\”:\”” & revResult & “\”, ” & ¬

    “\”isPlainTextNote\”:0, ” & ¬

    “\”autoCorrect\”:true, ” & ¬

    “\”decimalPlaces\”:0, ” & ¬

    “\”shouldEmail\”:1, ” & ¬

    “\”sortOrder\”:16, ” & ¬

    “\”sortField1Direction\”:\”asc\”, ” & ¬

    “\”printColumnWidth\”:80, ” & ¬

    “\”dbID\”:\”db-1a619b6d486c466c9fc32a1b4a494f00\”, ” & ¬

    “\”iconWidth\”:42, ” & ¬

    “\”listViewPosition\”:0, ” & ¬

    “\”photoQuality\”:1, ” & ¬

    “\”multiEnabled\”:true, ” & ¬

    “\”numberOfLines\”:5, ” & ¬

    “\”type\”:\”TFField\”, ” & ¬

    “\”photoWidth\”:0, ” & ¬

    “\”autoIncrement\”:false, ” & ¬

    “\”form\”:\”frm-76434fe883654a209512d39f2f716d87\”, ” & ¬

    “\”pickListColumns\”:1, ” & ¬

    “\”” & fieldName & “\”:\”” & fieldValue & “\”, ” & ¬

    “\”formulaReturnType\”:0, ” & ¬

    “\”inputControlType\”:\”default\”, ” & ¬

    “\”shouldPrint\”:1, ” & ¬

    “\”fieldType\”:\”text\”, ” & ¬

    “\”useAutoComplete\”:false, ” & ¬

    “\”shouldExport\”:1, ” & ¬

    “\”incrementAmount\”:1, ” & ¬

    “\”enableDataDetectors\”:1, ” & ¬

    “\”deviceName\”:\”David’s Mac Studio\”, ” & ¬

    “\”labelColour\”:\”0xFF4C4C4C\”, ” & ¬

    “\”viewSettingsInfo\”: {\”columns\”: {\”show\”:true,\”sort\”:16}}” & ¬

    “}”

     

    — Debug: Display JSON payload

    — display dialog “JSON Payload: ” & jsonPayload

     

    — URL to update the document

    set updateURL to couchdbURL & “/” & documentID

     

    — Create the shell command for the curl request

    set curlCommand to “curl -X PUT -u ” & couchdbUser & “:” & couchdbPassword & ” -H ‘Content-Type: application/json’ -d ‘” & jsonPayload & “‘ ” & updateURL

     

    — Debug: Display update command

    — display dialog “Update Command: ” & curlCommand

     

    — Run the shell command

    set updateResponse to do shell script curlCommand

     

    — Debug: Display update response

    — display dialog “Update Response: ” & updateResponse

     

    — Optional: Notify completion

    display notification “CouchDB document update request sent” with title “CouchDB Update”

Viewing 15 results - 331 through 345 (of 3,016 total)