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 - 391 through 405 (of 2,950 total)
  • Author
    Search Results
  • #50311
    Chris Ju
    Participant

    In general i want to solve the issue that the date and time “mdappointmentdatetime” in the following script is not passing to the date field of the new record. The value for example is “Freitag, 23. Februar 2024 um 13:00:00”. I think it hasn’t something to do with the format because it is accepted when inserting it manually. Maybe there is an timing issue. Also i have an field script in the form of the new record which needs the field to calculate an end date. The field script in generally works. Here is the script:

    function showErrorMessage(message) {
    let errorPrompter = Prompter.new();
    errorPrompter.cancelButtonTitle = '';
    errorPrompter.continueButtonTitle = 'Abbruch';
    errorPrompter.show(message, (status) => {
    // Error message has been shown to the user
    });
    }

    function confirmExecution(question) {
    return new Promise(function(resolve, reject) {
    let prompter = Prompter.new();
    prompter.cancelButtonTitle = 'Abbrechen';
    prompter.continueButtonTitle = 'Fortfahren';
    prompter.show(question, (status) => {
    if (status == true) {
    resolve('Fortfahren');
    } else {
    reject('Abbrechen');
    }
    });
    });
    }

    function createChildRecord() {
    // Fetch data from the clipboard
    var JSONdata = Utils.copyTextFromClipboard();
    var obj;

    // Try to parse the JSON data
    try {
    obj = JSON.parse(JSONdata);
    } catch (error) {
    console.log('Error parsing JSON from clipboard:', error);
    showErrorMessage("Zwischenablage enthält keine gültigen Daten (JSON string not valid).");
    return;
    }

    // Extract data from JSON
    var mdappointmentdatetime = obj.mdappointmentdatetime;
    var mdappointmentaddress = obj.mdappointmentaddress;
    var mdfilenum = obj.mdfilenum;
    var mdappointmentroom = obj.mdappointmentroom;

    // Format the confirmation message
    var confirmationMessage = 'Eintrag mit diesen Daten erstellen?' +
    '\n\n***** Datum/Uhrzeit: *****\n\n' + mdappointmentdatetime +
    '\n\n***** Adresse: *****\n\n' + mdappointmentaddress +
    '\n\n***** Aktenzeichen: *****\n\n' + mdfilenum +
    '\n\n***** Saal/Raum: *****\n\n' + mdappointmentroom;

    // Call the confirmExecution function with the formatted message
    confirmExecution(confirmationMessage)
    .then(() => {
    // User clicked 'Yes', proceed with creating the child record
    console.log("Creating child record with:", obj);

    // Get the parent form and record
    var parentForm = document.getFormWithId(obj.TfFilesFormId_hidden);
    var parentRecord = parentForm.getRecordWithId(obj.TfFilesRecordId_hidden);

    // Create a new child record in the specified field of the parent record
    var newChildRecord = parentRecord.addNewRecordToField('fld-77f19f359038497fbbe07a20454301f8');

    // Set field values for the new child record
    newChildRecord.setFieldValues({
    'fld-e4b947dd1f8042e6ba52e1a438cd0a01': mdappointmentdatetime,
    'fld-4997e582a89444b8a68f1f2126575042': mdappointmentaddress,
    'fld-de8d6fee8162434aa981686302d1f7f5': mdfilenum + "\n\n" + mdappointmentroom
    });

    // Save changes
    document.saveAllChanges();

    // Open the new child record
    var newRecordUrl = newChildRecord.getUrl();
    Utils.openUrl(newRecordUrl);

    })
    .catch(() => {
    // User clicked 'No', log the cancellation
    console.log('Record creation cancelled');
    });
    }
    // Call the function to create child record
    createChildRecord();

    • This reply was modified 1 year, 9 months ago by Chris Ju.
    • This reply was modified 1 year, 9 months ago by Chris Ju.
    #50306
    Brendan
    Keymaster

    Hi Cornelius,

    Yes, Tap Forms should run the script whenever the value for the field fld-8b1dde982f4849b7b6980b0a95b49a45 changes. Do you see any of your console log output at all when you change the value of that field?

    Is this a Field script? Do you have it set to return the proper Number type from the Script?

    Thanks,

    Brendan

    #50302
    Cornelius Fischer
    Participant

    Hi guys – I started playing with the field scripts. My first goal, try to use TapForms to generate offers and invoices. Therefore I need to calculate taxes. In my first trial I have a form to generate an offer with 2 positions.

    Basic options like:

    • Position name
    • amount
    • hourly rate
    • sum (amount*hourly rate)

    Now I calculate with a calculation field the net-total from sum-1 and sum-2. Now my taxes script comes into play. Im using a script field with the following script to calculate the tax from the net-total. Thx to ChatGPT by the way for the script (i’m not a programmer)..

    // Aufruf der Funktion
    berechneMehrwertsteuer();
    
    // Funktion zur Rundung auf 0.05
    function roundToNearestFiveCents(value) {
    return Math.ceil(value / 0.05) * 0.05;
    }
    
    // Funktion zur Berechnung der Mehrwertsteuer mit Rundung auf 0.05
    function berechneMehrwertsteuer() {
    // Hole die Nettosumme aus dem Formularfeld
    var nettoSumme = record.getFieldValue('fld-8b1dde982f4849b7b6980b0a95b49a45');
    
    // Prüfe, ob die Nettosumme gültig ist
    if (isNaN(nettoSumme)) {
    console.error('Ungültige Nettosumme');
    return;
    }
    
    // Setze den Mehrwertsteuersatz
    var mehrwertsteuersatz = 8.1;
    
    // Berechne den Mehrwertsteueranteil
    var mehrwertsteueranteil = nettoSumme * (mehrwertsteuersatz / 100);
    
    // Runde auf 0.05 genau
    mehrwertsteueranteil = roundToNearestFiveCents(mehrwertsteueranteil);
    
    // Gib das Ergebnis in der Konsole aus
    console.log('Mehrwertsteueranteil: ' + mehrwertsteueranteil);
    
    // Rückgabe des Ergebnisses (falls notwendig)
    return mehrwertsteueranteil;
    }

     

    Now my problem, whenever I change something like the amout from pos 1 oder pos 2, the net-total is recalculated but NOT the tax. When I understand the FAQ for script field right, the script should automatically run, when the reference field (record.getFieldValue) changes.

    So why is my script not updating my tax field? 🤷‍♂️

    • This topic was modified 1 year, 9 months ago by Brendan. Reason: formatted the code
    #50301
    Brendan
    Keymaster

    Hi Torsten,

    There’s no trigger function to run scripts when a record is deleted.

    Sorry about that.

    Brendan

    #50300
    Torsten Reim
    Participant

    Dear members,

    how can I trigger a script if one or more record was deleted?

    I have developed code that triggers a script if I added a record, works fine.

     

    Regards from germany,

    Torsten

    Samsei
    Participant

    I’ll try to explain my problem as simply as possible. I work with the homeless and am currently in the process of creating a database. Basically, I have to deal with a relatively large number of different people every day who give me individual tasks. I have therefore created a table of tasks to be completed for each client. Now I am looking for a way to display all the tasks in order to get an overview.The idea behind this is that I don’t have to click on each client individually to see what still needs to be done this month, for example.

    I could not create a table to import the data from another forumlar. However, linking to the document does not work (as I understand it) even if the data is in a table.
    However, I have not found a script option either.

    Does anyone have any ideas on how I can implement this?

     

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

    In reply to: iOS Shortcuts

    Brendan
    Keymaster

    Hi Tiago,

    The shortcuts function in Tap Forms for iOS will only allow you to call to a Form script. On the Form Script Editor there’s a function for adding the script to Siri. You would need to write a script to search your records for the one that matches your criteria.

    It’s no small task though for someone without a programming background. You can take a look at the Scripting instructions here though:

    https://www.tapforms.com/help-mac/5.3/en/topic/scripts

    Thanks,

    Brendan

    #50282
    Fernando DS
    Participant

    Excuse me. I have sent another script. I have done very much.

    the last is this:

     

    function updateRunningTotal(record) {
    var importe = parseFloat(record.getFieldValue(‘fld-1cff7a1e6d3d4c68a081fa20be53ba48’)) || 0;
    var pagos = parseFloat(record.getFieldValue(‘fld-c4d4d96ce0584cef99a8422512ece4e6’)) || 0;

    // Calcular el nuevo Saldo
    var nuevoSaldo = importe – pagos;

    // Actualizar el campo Saldo en el registro actual
    record.setFieldValue(‘fld-db305c87f3db46d0bbcaaf95dcb47858’, nuevoSaldo);

    console.log(“Importe: ” + importe);
    console.log(“Pagos: ” + pagos);
    console.log(“Nuevo Saldo: ” + nuevoSaldo);
    }

    // Llamar a esta función cada vez que cambie Importe o Pagos
    updateRunningTotal(record);

    #50281
    Fernando DS
    Participant

    Thank you Glen.

    I must say that my records are independent. Every record is a different debt.

    I have done the following script, but it continues not working. The saldo field is the result of importe-pagos, not saldo-pagos as I want. Any sugestions on the script?

     

    function updateRunningTotal(records) {
    records.forEach(function(record) {
    var importe = parseFloat(record.getFieldValue(‘fld-1cff7a1e6d3d4c68a081fa20be53ba48’)) || 0;
    var pagos = parseFloat(record.getFieldValue(‘fld-c4d4d96ce0584cef99a8422512ece4e6’)) || 0;
    var saldoAnterior = parseFloat(record.getFieldValue(‘fld-db305c87f3db46d0bbcaaf95dcb47858’)) || 0;

    // Calcular el nuevo Saldo basándose en el Saldo anterior y los Pagos
    var nuevoSaldo = saldoAnterior – pagos;

    // Actualizar el campo Saldo en el registro actual
    record.setFieldValue(‘fld-db305c87f3db46d0bbcaaf95dcb47858’, nuevoSaldo);

    console.log(“Importe: ” + importe);
    console.log(“Pagos: ” + pagos);
    console.log(“Saldo Anterior: ” + saldoAnterior);
    console.log(“Nuevo Saldo: ” + nuevoSaldo);
    });
    }

    var allRecords = form.getRecords();

    // Llamar a esta función para actualizar el Saldo basándose en el Saldo anterior y los Pagos en todos los registros
    updateRunningTotal(allRecords);

    #50280
    Glen Forister
    Participant

    You need to be able to access the total information from the previous record.

    If you keep all your records in date order, then you might be able to use the script I was given for a simple purpose as an example,

    See:https://www.tapforms.com/forums/topic/previous-record-problem/

    You can also download the file and see how it relates.  Read the info about the previous record number id  – tricky.

    Good luck.

    #50279
    Fernando DS
    Participant

    Hi Brendan,

    Thank you very much.

    I don't quite understand what you want to tell me.
    I think I must have expressed myself poorly. I'm going to give a practical example to see if it becomes clearer.
    Someone owes me 1000 dollars, which I write in the Amount field.
    This same amount appears in the Balance field, by the formula Balance = Amount-Payments.
    They make me a payment of $500, which I write in the Payments field.
    And in the Balance field, by the aforementioned formula, there are 500 dollars left.
    Well, now they make another payment of another 500 dollars. If I write 500 in the Payments field, the Balance field will not remain at 0, but at 500. To make it remain at 0 I would have to enter the total amount paid so far, that is, 1000 dollars.
    This is not difficult in this example, but with other amounts I have to make the sum separately and enter it in Payments.
    What I want is to be able to enter partial payments, not have to enter the total amount paid each time.
    That is, in the case of the example, I would make 2 entries of $500 in the Payments field, and Balance would remain at 0.
    Now I have to make a note of 500 and another of 1000.
    I hope I am explaining myself well.
    I have tried the script thing by setting the Balance field as a script type. But I haven't gotten it to work for me.
    Anyway, excuse me for my bad English. I hope that now it is clearer to you what I want to do.
    
    Thank you,
    
    Fernando

     

     
    #50278
    Brendan
    Keymaster

    Hi Fernando,

    There’s no direct function for computing a running total in Tap Forms, which is what it sounds like you want to do. Tap Forms has access to the current record’s data and it can get a total for all records.

    You could possibly achieve what you want with a script that you can run which will loop through all your records and compute the running total and update a field in each record to include the total of the records up until that point.

    There’s help in the online user manual about scripting here:

    https://www.tapforms.com/help-mac/5.3/en/topic/scripts

    Thanks,

    Brendan

    #50272
    Daniel Leu
    Participant

    Yeah, it’s a bit tricky. In the form inspector panel,  select the field tab followed by the ‘previous’ field. Then scroll down. Underneath the Description field is the field ID.

     

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

    Cheers, Daniel

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

    #50268
    Daniel Leu
    Participant

    Hi Glen, in your original script, you were reading the previous total from the wrong field. Now it should work as expected:

    function toHrsMin(sec){
    let str = "";
    let h = Math.floor(sec / 3600);
    let m = (sec / 60) % 60;
    return h + ' hr, ' + m + ' mins';
    }
    function Accum_Tot() {
    var records = form.getRecords();
        var currentRecordIndex = records.indexOf(record);
        if (currentRecordIndex > 0) {
            var previousRecord = records[currentRecordIndex-1];
            var previous_total = previousRecord.getFieldValue('fld-b2f9616bf5e44fb4880ad9addd2afc6e');
        } else {
        var previous_total = 0;
        }
    var today = record.getFieldValue('fld-44acc9d2314f41beb3f2257ace5bae01');
    var total = today + parseInt(previous_total);
    console.log("Today: " + toHrsMin(today))
    console.log("Previous: " + toHrsMin(previous_total))
    console.log("Total: " + toHrsMin(total))
    return total;
    }
    Accum_Tot();
    • This reply was modified 1 year, 10 months ago by Daniel Leu.

    Cheers, Daniel

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

    #50265
    Torsten Reim
    Participant

    Dear members,

    how can I prevent that my form field script runs three times? I need 3 event listeners for my form. But this code should only run once.

    var letzter_eintrag = record.getFieldValue(‘fld-827f7254f04c462f887323172ef309ca’);
    var brief_erstellt = record.getFieldValue(‘fld-8295048b2bee4f959bb952914117c266’);
    var brief_versandt = record.getFieldValue(‘fld-c1e5d2c7de1844d2ae50fdcbe118232d’);

    function ….{
    call another function;

    }

    ……

Viewing 15 results - 391 through 405 (of 2,950 total)