Blog  |  Support  |  Forums

Search Results for 'script'

Viewing 15 results - 46 through 60 (of 2,612 total)
  • Author
    Search Results
  • #50357
    Ray Robillard
    Participant

    Saw your explanations on this thread, but it didn’t work for me.  I was able to change two var for const with getId(), and now the script won’t auto execute…

     

    Source : https://www.tapforms.com/forums/topic/pre-processing-field-entry/

    function Update_Last_Viewed_Date() {
        const watched_date_id = form.getFieldNamed(‘Watched date’).getId();
        var date_to_log = record.getFieldValue(watched_date_id);
        const viewings_id = form.getFieldNamed(‘Visionnements’).getId();
        var newRecord = record.addNewRecordToField(viewings_id);
        var date_id = ‘fld-da18c2d927f443a3a5cac5b35f705aff’;
        newRecord.setFieldValue(date_id, date_to_log);
        document.saveAllChanges();
    }
    Update_Last_Viewed_Date();
    If I execute it manually, I get one row inserted with the correct value.
    #50355
    Ray Robillard
    Participant

    Got it, thanks!  It’s working now, but there seems to be a bug, or something, the script is executing twice, resulting in two rows being inserted in the table, with the same values (the date I input).  Here’s my script :

     

    function Update_Last_Viewed_Date() {

        var watched_date_id = ‘fld-0d50c9c744b14f89bcfcaa1295650845’;
        var date_to_log = record.getFieldValue(watched_date_id);

        var viewings_id = ‘fld-edf6c517ee814c059b9abe34846eb65c’;
        var newRecord = record.addNewRecordToField(viewings_id);
        var date_id = ‘fld-da18c2d927f443a3a5cac5b35f705aff’;

        newRecord.setFieldValue(date_id, date_to_log);

        document.saveAllChanges();

    }

    Update_Last_Viewed_Date();

    I checked to make sure, the script exists only in one entry, amongst the list of fields.  I also did different tests (empty viewing history list, list with one date already existing, quit and relaunch Tap Forms) and every time I input a new viewed date, it gets inserted twice.

    Am I doing something wrong ?

    Attachments:
    You must be logged in to view attached files.
    #50353
    Daniel Leu
    Participant

    Make it a field script instead of a form script.

    #50352
    Ray Robillard
    Participant

    newRecord.. Of course !!  Thanks, new record added and contains the desired value.

     

    Now, how can I have this script triggered automatically ?

    #50348
    Ray Robillard
    Participant

    I have a movie database in which I’d like to keep an history of every time I watch my movies.  I have a field in which I save the last viewing date.  With a script, I was hoping to copy this value to an history table field.

    So far, I am able to get the current watched date (console.log shows that I am ok there), add a blank record to my table (I can see that when I run the script manually) but I am at a loss to update this newly added record and trigger the script automatically.

    Here’s the script :

    function Update_Last_Viewed_Date() {
         var watched_date_id = ‘fld-0d50c9c744b14f89bcfcaa1295650845’;
         var date_to_log = record.getFieldValue(watched_date_id);
         var viewings_id = ‘fld-edf6c517ee814c059b9abe34846eb65c’;
         var newRecord = record.addNewRecordToField(viewings_id);
         var date_id = ‘fld-da18c2d927f443a3a5cac5b35f705aff’;
         record.setFieldValue(date_id, date_to_log);
         document.saveAllChanges();
    }
    Update_Last_Viewed_Date();
    How can I update the recently added record ?  And, most importantly, how do I trigger this script ?  I read that it should be triggered automatically since I used “getfieldvalue” of the last viewing date.  But it doesn’t.  If I input a new value in that field, it doesn’t call the script (because no blank record is added to the table).

    I added screen captures to better explain what I am trying to do.

    Thanks  in advance !

    Attachments:
    You must be logged in to view attached files.
    #50326
    Cornelius Fischer
    Participant

    Hi Brendan

    I just checked what the console is showing, when I change values. Nothing.. 🤷‍♂️ When I hit the “refresh entry list” Button on the bottom left, the script field gehts calculated.

    I attached a screenshot of my test form. I’m using number and calculation fields for calculating the net-total. This works fine. For the tax, I created a script field.

     

    @Torsten

    To be honest, I’m a photographer and not a programmer. Don’t have clue what kind of data type the script output is.. 🫣 I even don’t know how the calculated value is pasted into the form field. I only can say, if I manually activate the script, the script-form-field is updated with the correct tax value. 🤷‍♂️ So the script itself (from ChatGPT) seems to work.

    Attachments:
    You must be logged in to view attached files.
    #50314
    Chris Ju
    Participant

    I solved the issue writing to a date field using for example:

    var mdappointmentdatetime = new Date(obj.mdappointmentdatetime);

    and using a python script to convert the non standard date/time to a javascript friendly format.

    Nevertheless the prompter class documentation does not show us something for control types and default values.

    • This reply was modified 4 months ago by Chris Ju.
    • This reply was modified 4 months ago by Chris Ju.
    • This reply was modified 4 months ago by Chris Ju.
    • This reply was modified 4 months ago by Chris Ju.
    #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 4 months ago by Chris Ju.
    • This reply was modified 4 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 4 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

    #50296
    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);

Viewing 15 results - 46 through 60 (of 2,612 total)
 
Apple, the Apple logo, iPad, iPhone, and iPod touch are trademarks of Apple Inc., registered in the U.S. and other countries. App Store is a service mark of Apple Inc.