Blog  |  Support  |  Forums

Search Results for 'script'

Viewing 15 results - 16 through 30 (of 2,612 total)
  • Author
    Search Results
  • Paul Wirth
    Participant

    I have a script that concatenates a bunch of linked records as text and inserts the concatenated text into a field, so that I can easily scroll through a bunch of entries at once.

    Currently, the script runs any time a linked field is updated, so every record has concatenated text stored in its designated field. But I don’t really need that text stored, since it’s redundant. It’s just useful to browse through the text when needed.

    What would work nicely is if there was a script command to produce a modal or popover for viewing scrollable text that can be dismissed. The idea is that this would be ephemeral. Click a button to run the script, which concatenates the field and displays the full text for viewing, but doesn’t store it to the file.

    The Prompter() class would work, except any text beyond a few lines is cut off and not scrollable.

    Maybe this is such a unique request that it isn’t worth developing, but I thought I’d ask!

    #50576
    FrAnksch
    Participant

    Daniel, thank you very much.
    Since I’m a script newbie, I had a problem to set this “isRecord” property, but now after several trials, I finally figured it out.

    one additional question:

    With my script below, I mark the current entry of my dairy (“today’s record”) greenish and as favorite.
    Therefor I use a “helper calculation field” (tageseit) that calculates the difference between date of record and today (>>DAYS(X;Y)<<),  which then is checked in an if query.
    This is working as expected, but how can I get this calculation (of entire days) done in the script? If I calculate with date fields, I get “seconds” as result, not entire days.

    Thanks for your help!

    my Script:

    function SkriptMarkToday() {

    var tageseit_id = ‘fld-6826c8b388e046c5ab5b10144fe499db’;
    var tageseit = record.getFieldValue(tageseit_id);
    var forcefav_id = ‘fld-aa6d11f990724703969cd07d85037f71’;
    var forcefav = record.getFieldValue(forcefav_id);

    form.selectRecord();

    if (tageseit == 0) {
    record.setRecordColor(“#66DD77”);
    record.isFavourite=1;
    console.log(“als heute und als FAV markiert”);

    } else {
    if (forcefav == 0) {
    record.isFavourite=0;
    console.log(“FAV deaktiviert”)
    }
    record.setRecordColor(null);
    console.log(“nicht heute”);
    }
    form.saveAllChanges();

    }

    SkriptMarkToday();

    • This reply was modified 2 months ago by FrAnksch. Reason: Tried to format the code - don't know how
    • This reply was modified 2 months ago by FrAnksch.
    #50573
    FrAnksch
    Participant

    Is this feature available in the meantime?

    I’m currently looking for a way to mark the current dairy record (of “today”) as favourite automatically via script…

    #50566
    Victor Warner
    Participant

    I would like to know, with a script, to add the value to a field in all the records in a linked form.

    Eg first form (Clients) has a linked to Form (Work), and I wish to add a value to a field in the second form for the records related to a record in the first form, with a script. In the example database attached, adding ‘yes’ to the paid field in the Work form for any of the records linked to one of the persons in the first.

    I am (vaguely) aware that I need to use a loop but cannot work out how to structure the script  (or what actions/commands I need to use).

    Any help gratefully received.

    Attachments:
    You must be logged in to view attached files.
    #50556
    Victor Warner
    Participant

    I have the following script which writes data from a .csv file to several fields. It does so by adding a new record and then writing the data to the fields. I would like to know how to do so to the currently selected record.

    Any help would be gratefully received.

    // this imports the Papa Parse script
    
    form.runScriptNamed('PapaParse');
    
    // replace with your field ID's
    
    var date_of_invoice_id = 'fld-1b800a91fac14b329ef47d23c7cdacb0';
    var date_paid_id = 'fld-60fa17dec2a24d9588ce4aafa3dccd5c';
    var date_of_receipt_id = 'fld-9ed8f17873a642b4a2ee58ff24eba421';
    var method_of_payment_id = 'fld-15b719109ab64053a5c46427622f81f5';
    var payment_notes_id = 'fld-3a22501b3096443f8f92c6cf6c7e2de5';
    
    function Import_Entries() {
    //let filename = "file:///Users/victor/vwdata/data/Notary/client database/not in use/FileMaker/notary/vPaymentDetails.csv";
    let filename = "file:///Users/victor/Library/Mobile Documents/com~apple~CloudDocs/filedtoday/vPaymentDetails.csv";
    
    &nbsp;
    
    let csvFile = Utils.getTextFromUrl(filename);
    
    if (!csvFile) {
    console.log("No CSV file?");
    return
    }
    
    var output = Papa.parse(csvFile);
    
    // abort if there are any errors and log to console.
    if (output.errors.length > 0) {
    console.log(errors.join("\n"));
    return;
    }
    
    // read each line
    for (let line of output.data) {
    var newRecord = form.addNewRecord();
    newRecord.setFieldValues({
    [date_of_invoice_id]: line[0],
    [date_paid_id]: line[1],
    [date_of_receipt_id]: line[2],
    [method_of_payment_id]: line[3],
    [payment_notes_id]: line[4],
    });
    //var job_completed_id = 'fld-ba0622aac1ea42ff9e5e9272c4314fa7';
    
    //record.setFieldValue(job_completed_id,"Yes");
    
    document.saveAllChanges();
    }
    }
    
    // Import entries to form "Who" from filename "Whom.csv"
    Import_Entries("Notarial Act", "vPaymentDetails.csv");
    
    FrAnksch
    Participant
    I was looking for a way, to collect all linked records of a 1:n related child form within one note filed of the parent form, in order to use these information for further purposes.
    Since I am NOT familiar with software development and an absolutely newbie to scripting, I was searching the TF forums, and with the help of the Child Records Loop  snippet and some tips and examples Brendan published here in the forum, I built a template for “Collecting Child Records in the Parent form”, that works as I expected (I am on iOS, but the template should work on mac as well).
    I’m quite sure there are many other “non-software-development” users with minor scripting skills, so I prepared the templates with “speaking” names in the hope that it is understandable even for newbies.
    Sorry programmers, this is a beginners guide ;-)
    There are 2 forms:
    – ParentForm (PF)
    – ChildForm (CF)
    Within the CF there are 4 different records (children), each with several properties. In one additional field “AllProperties” I put all properties for each child together (calculation field, separate field values are connected via “concat” formula).
    The PF is linked with the CF via “1:n relation”. Within this PF there are 2 records (Parent1 and Parent2). Via the field “children” (relation field to child form), each Parent is linked with 2 children.
    You can select the children with the “selection checkbox”.
    Then there is a calculation field “children count” which shows automatically the number of selected children for each Parent.
    Additionally there is a note field “CollectionOfChildren”, which automatically shows the information for the “AllProperties” field for all linked children, one line for each child. Since this is one field with one text (consisting of all properties of all linked children), the text is very clear at a glance and is e.g. printed very nice or could be used for further purposes.
    The information for this target “note field” is generated in a script field “ScriptCollectChildren”, which is hidden and thus not visible in the form (only when you edit the form).
    The script code is listed below, you do NOT have to adapt the code anyhow, just replace the three (red) fieldIDs (fld-4e07f10f46………) in the upper part of the code.
    You can use this forms and adapt it according to your needs, or you can implement such fields to your already existing forms, copy the script code, paste it into your script fiel and replace the field IDs with yours.
    I hope this template (and/or the script) helps some of you, at least if you are a “rookie” like I am.
    ScriptCode (@programmers: sorry for bad indentation, this was written in TF iOS app)
    function CollectChildren() {
    var parentform_Children_id = ‘fld-4e07f10f46c84c0c99c5ca723ee42ad5’;//table of sourcedata (1:n LinkField to ChildForm)
    var parentform_Children = record.getFieldValue(parentform_Children_id); //datasets of sourcedata
    var childform_RequiredProperty_id = ‘fld-570a6131139842288f18683e91833f6c’;//field of interest of sourcedata
    var parentform_CollectionOfChildren_id = ‘fld-557c63ce9156491e8f8891b00c0def5b’; //tagetfield for collected data from field of interest
    var temp_CurrentChild = []; //array for collecting data
    //running through all datasets & collecting data into temp. array
    for (var index = 0, count = parentform_Children.length; index < count; index++){
          var childform_RequiredProperty = parentform_Children[index].getFieldValue(childform_RequiredProperty_id);
    if (childform_RequiredProperty) {
    temp_CurrentChild.push(childform_RequiredProperty);
    }
    }
    //joining collected data from temp. array into temp. variable
    var temp_ChildrenList = temp_CurrentChild.join(“,\r”);
    //writing joined collection from temp. variable into target field
    record.setFieldValue(parentform_CollectionOfChildren_id, temp_ChildrenList);
    return temp_ChildrenList;
    form.saveAllChanges();
    }
    CollectChildren();
    • This topic was modified 2 months, 1 week ago by FrAnksch. Reason: format optimization
    • This topic was modified 2 months, 1 week ago by Brendan. Reason: tagged code as code
    • This topic was modified 2 months, 1 week ago by Brendan. Reason: tagged code as code
    • This topic was modified 2 months, 1 week ago by Brendan.
    • This topic was modified 2 months, 1 week ago by Brendan.
    Attachments:
    You must be logged in to view attached files.
    #50522
    Shannon Miles
    Participant

    Hello. I thought I’d share the movie library template I created to keep track of both my physical media (DVD, Blu-ray, etc.) and digital library. It’s essentially a main form with the basic movie information with two linked forms, one for physical media and one for digital.  There is also a script to fill in the basic information using the TMDB Number/ID. I cobbled it together from these two topics: https://www.tapforms.com/forums/topic/watched-tv-shows/ and https://www.tapforms.com/forums/topic/get-movie-details-from-themoviedb-api-help-needed/. I know not this odd thing called JavaScript, but am a copy and paste demon, so thanks to everyone who contributed to this code. There are instructions in the script for use.

    P.S. Programmers beware, I don’t know the indent rules, so it may cause an eye twitch.

    Attachments:
    You must be logged in to view attached files.
    #50511
    Giovanni Vittoria
    Participant

    Thank you Daniel!

    I checked this and you”re absolutely right:

    the script IS working, but the updated results are not displayed correctly on my iPhone. The temporarily arranged return value appears in the script field.

    The date fields are displayed correctly as soon as I go back to the entry list and back to a single entry, even without manual refresh (I am on iPhone).
    On my iPad (with list view on the lefthand side) it is clearly visible, that the date fields are updated as soon the checkbox is changed.
    So everything is Ok for me.
    Thanks for opening my eyes! ;-)

    cheers, Giovanni

    #50509
    Daniel Leu
    Participant

    I do think that the script runs as you expect it to run, but the issue is related to displaying the updated results. You could check that the script runs by adding a return value or putting something in the console.

    I’ve seen this before that TapForms doesn’t display updated fields. Unfortunately, the only solution is the one you’re using :-(

    #50502
    Giovanni Vittoria
    Participant

    Hi,

    first if all: I’m a absolute rookie in terms of scripting, so SORRY for the bad code & for my stupid questions. But I’m willing to learn ;-)

    I have 2 date fields and want them to show the date when a boolean field (checkbox) was checked or unchecked.
    Within the form I use a script-field with the script below.

    The code  is not nice, but it works in general. But only if the entry is manually refreshed (iOS: pull down).

    Other tests with website-field (according to https://www.tapforms.com/forums/topic/pre-processing-field-entry/) work automatically when the entry is stored.
    I would like to have my script running as soon as the checkbox is checked or unchecked.

    Could  anybody please optimize my code or help me to get this work?

    Thanks!

    function Checkdate() {

    var check_field_id = “fld-abc”;
    var date_field1_id = “fld-xyz”;
    var date_field2_id = “fld-zyx”;

    var check_value = record.getFieldValue(check_field_id);
    var date1_value = record.getFieldValue(date_field1_id);
    var date2_value = record.getFieldValue(date_field2_id);

    if (check_value == 1)
    {
    if (date1_value == null)
    {
    record.setFieldValue(date_field1_id, new Date());
    record.setFieldValue(date_field2_id, null);
    }
    }
    else
    {
    if (date2_value == null)
    {
    record.setFieldValue(date_field2_id, new Date());
    record.setFieldValue(date_field1_id, null);
    }
    }
    form.saveAllChanges();

    }

    Checkdate();

    cheers, Giovanni

    #50496
    Daniel Leu
    Participant

    Default values are working, but the default parameter is the 5th one:

    var value_1;
    var value_2;
    function script() {
    var callbackFunction = function() {
    console.log(value_1);
    console.log(value_2);
    };
    let prompter = Prompter.new();
    prompter.addParameter('Label 1', 'value_1', '','','Default Value')
    .addParameter('Label 2', 'value_2', 'popup', ['Option 1', 'Option 2'], 'Option 1')
    .show('Message prompt', callbackFunction);
    };
    script();
    #50454
    Fernando DS
    Participant

    <p style=”text-align: left;”>I send another script later and I think it’s more complete.

    </p>
    var fecha_pago_o_cobro_id = ‘fld-3671b67b092b4b3b949984292c023511’;
    var pagos_y_acumulado_id = ‘fld-a1ee93e141f34774be95df31d316be12’;
    var importes_y_acumulado_id = ‘fld-d72e37e939fe476e820ff4f3c4ef12c7’;
    var fecha_proximo_pago_o_cobro_id = ‘fld-51be737772e840d2b4d365bd1f5230cd’;
    var saldo_proximo_pago_o_cobro_id = ‘fld-a554770fd7834b22802b65c488be9f0d’;

    var fechaActual = new Date();
    var registros = form.getRecords();

    registros.forEach(function (registro) {
    var calculos = registro.getFieldValue(‘fld-d8a58dbf35914f3c858c6dfb880c1c48’) || [];

    if (calculos.length > 0) {
    var ultimoCalculo = calculos[calculos.length – 1];
    var fechaPagoCobro = new Date(ultimoCalculo[fecha_pago_o_cobro_id]);
    var importe = ultimoCalculo[importes_y_acumulado_id];

    if (fechaPagoCobro < fechaActual) {
    // Cumplimentar el campo Pagos con el valor del campo Importes para saldar el pago o cobro
    ultimoCalculo[pagos_y_acumulado_id] = importe;

    // Determinar la nueva fecha de pago o cobro
    var periodicidadTexto = registro.getFieldValue(‘fld-aaba9a24064a4a8893a3963f7cbe8595’);
    var nuevaFechaProximoPagoCobro = new Date(fechaPagoCobro);
    switch (periodicidadTexto) {
    case ‘Mensual’:
    nuevaFechaProximoPagoCobro.setMonth(nuevaFechaProximoPagoCobro.getMonth() + 1);
    break;
    case ‘Bimensual’:
    nuevaFechaProximoPagoCobro.setMonth(nuevaFechaProximoPagoCobro.getMonth() + 2);
    break;
    case ‘Trimestral’:
    nuevaFechaProximoPagoCobro.setMonth(nuevaFechaProximoPagoCobro.getMonth() + 3);
    break;
    case ‘Semestral’:
    nuevaFechaProximoPagoCobro.setMonth(nuevaFechaProximoPagoCobro.getMonth() + 6);
    break;
    case ‘Anual’:
    nuevaFechaProximoPagoCobro.setFullYear(nuevaFechaProximoPagoCobro.getFullYear() + 1);
    break;
    // Añadir más casos de periodicidad si es necesario
    default:
    console.error(‘Periodicidad no reconocida: ‘ + periodicidadTexto);
    break;
    }

    // Crear una nueva línea con la nueva fecha de pago o cobro y el mismo importe
    var nuevoCalculo = {
    ‘fecha_pago_o_cobro_id’: nuevaFechaProximoPagoCobro,
    ‘importes_y_acumulado_id’: importe,
    ‘pagos_y_acumulado_id’: ”
    };
    calculos.push(nuevoCalculo);

    // Actualizar los campos fuera de la tabla ‘Cálculos’
    registro.setFieldValue(fecha_proximo_pago_o_cobro_id, nuevaFechaProximoPagoCobro);
    // No es necesario actualizar ‘Saldo/próximo pago o cobro’ si es un campo calculado automáticamente

    // Guardar los cambios en el registro actual
    registro.setFieldValue(‘fld-d8a58dbf35914f3c858c6dfb880c1c48’, calculos);
    }
    }
    });

    form.saveAllChanges();

    #50453
    Fernando DS
    Participant
    • Hi everybody,

      I have an income and expense form and I want to automate it as much as possible. To do this, and with the invaluable help of my friend ChatGPT, I have made the script that I am sending you. What I want is for the last pending payments or collections to be credited when the script is executed, if the current date is later than the date of said payments or collections. The payment records are in a table-type field called “Calculations”, which includes the fields: – “Payment or collection date”, date type field, is the expected date for payment or collection. – “Amounts and accumulated”, numerical field, is the amount to be paid or collected. – “Payments and accruals”, numerical field, is filled in with the value of the Amounts field when the Payment Date arrives. What the script intends is that when the Payment or Collection Date is before the current date, the script will be executed and the following actions will occur: In the line of the last pending payment, the Payments field will be filled with the value of the Amounts field, so that payment or collection will be skipped. At the same time, a new line will be created with the new Payment or Collection Date and the new Amount, which is always the same, and therefore will copy the one imported from the previous movement. Regarding the new date, the script will take into account the “Periodicity” field, a text field that marks the type of period that passes between one movement and the next, monthly, annual, etc., and which is also outside the Calculations table. And with this the next pending payment or collection will be fulfilled. 2 more fields will also be fulfilled, which are outside the Calculations table: – Next payment or collection date, date type field, which will copy the date of the last pending payment or collection that has been created. – Balance/next payment or collection, field calculated with a formula, which is the balance between the totals of the Amounts and the Payments. Here the new balance will be incorporated, which will be equal to the previous one. And that would be it. I want to clarify that I also have records with different imports, but I find it very difficult to measure these in a script. Each record in the form is a different payment or collection and are independent of each other. Without prejudice to the fact that the amounts are added to obtain totals and balances.
      Obviously the script does not work. It has no errors in the console, but not working.

    • Anyway, I hope I have explained myself. Although I will clarify any doubts. And this is the script

     

    var fechaActual = new Date();
    var registros = form.getRecords();

    registros.forEach(function (registro) {
    var calculos = registro.getFieldValue(‘fld-d8a58dbf35914f3c858c6dfb880c1c48’) || [];
    var fechaProximoPagoCobro = registro.getFieldValue(‘fld-3671b67b092b4b3b949984292c023511’);
    var saldoProximoPagoCobro = registro.getFieldValue(‘fld-a554770fd7834b22802b65c488be9f0d’);
    var periodicidadTexto = registro.getFieldValue(‘fld-aaba9a24064a4a8893a3963f7cbe8595’);
    if (calculos.length > 0 && fechaProximoPagoCobro && saldoProximoPagoCobro && periodicidadTexto) {
    var fechaUltimoCalculo = new Date(calculos[calculos.length – 1].fecha_pago_o_cobro_id);

    // Si la última fecha de pago es anterior a la fecha actual
    if (fechaUltimoCalculo < fechaActual) {
    var nuevaFecha = new Date(fechaUltimoCalculo);
    var meses = { ‘Mensual’: 1, ‘Bimensual’: 2, ‘Trimestral’: 3, ‘Semestral’: 6, ‘Anual’: 12 };
    var dias = { ‘7 días’: 7 };

    // Añadir tiempo a la fecha según la periodicidad
    if (meses[periodicidadTexto]) {
    nuevaFecha.setMonth(nuevaFecha.getMonth() + meses[periodicidadTexto]);
    } else if (dias[periodicidadTexto]) {
    nuevaFecha.setDate(nuevaFecha.getDate() + dias[periodicidadTexto]);
    }

    // Si la nueva fecha es en el futuro, añadimos una nueva entrada
    if (nuevaFecha > fechaActual) {
    var ultimoImporte = calculos[calculos.length – 1].importes_y_acumulado_id;
    calculos.push({
    fecha_pago_o_cobro_id: nuevaFecha,
    importes_y_acumulado_id: ultimoImporte,
    pagos_y_acumulado_id: ”
    });
    }

    // Actualizamos el campo ‘Pagos y acumulado’ del último cálculo
    calculos[calculos.length – 1].pagos_y_acumulado_id = saldoProximoPagoCobro;

    // Guardamos los cambios en el registro
    registro.setFieldValue(‘fld-d8a58dbf35914f3c858c6dfb880c1c48’, calculos);

    form.saveRecord(registro);
    }
    }
    });

     

    Thank you in advance for your kind help.

    #50452

    In reply to:

    Fernando DS
    Participant
    • I have an income and expense form and I want to automate it as much as possible. To do this, and with the invaluable help of my friend ChatGPT, I have made the script that I am sending you. What I want is for the last pending payments or collections to be credited when the script is executed, if the current date is later than the date of said payments or collections. The payment records are in a table-type field called “Calculations”, which includes the fields: – “Payment or collection date”, date type field, is the expected date for payment or collection. – “Amounts and accumulated”, numerical field, is the amount to be paid or collected. – “Payments and accumulated”, numerical field, is filled in with the value of the Amounts field when the Payment Date arrives. What the script intends is that when the Payment or Collection Date is before the current date, the script is executed and the following actions occur: In the line of the last pending payment, the Payments field will be filled in with the value of the Amounts field, so that payment or collection will be settled. At the same time, a new line will be created with the new Payment or Collection Date and the new Amount, which is always the same, and therefore will copy the amount of the previous movement. Regarding the new date, the script will take into account the “Periodicity” field, a text field that marks the type of period that passes between one movement and the next, monthly, annual, etc., and which is also outside the Calculations table. And with this the next pending payment or collection will be completed. Two more fields will also be completed, which are outside the Calculations table: – Next payment or collection date, date type field, which will copy the date of the last pending payment or collection that has been created. – Balance/next payment or collection, field calculated with a formula, which is the balance between the totals of the Amounts and the Payments. Here the new balance will be incorporated, which will be equal to the previous one. And that would be it. I want to clarify that I also have records with different amounts, but I find it very difficult to put these in a script. Each record in the form is a different payment or collection and are independent of each other. Without prejudice to the fact that the amounts are added to obtain totals and balances. Anyway, I hope I have explained myself. Although I will clarify any doubts. And this is the script

     

    var fechaActual = new Date();
    var registros = form.getRecords();

    registros.forEach(function (registro) {
    var calculos = registro.getFieldValue(‘fld-d8a58dbf35914f3c858c6dfb880c1c48’) || [];
    var fechaProximoPagoCobro = registro.getFieldValue(‘fld-3671b67b092b4b3b949984292c023511’);
    var saldoProximoPagoCobro = registro.getFieldValue(‘fld-a554770fd7834b22802b65c488be9f0d’);
    var periodicidadTexto = registro.getFieldValue(‘fld-aaba9a24064a4a8893a3963f7cbe8595’);
    if (calculos.length > 0 && fechaProximoPagoCobro && saldoProximoPagoCobro && periodicidadTexto) {
    var fechaUltimoCalculo = new Date(calculos[calculos.length – 1].fecha_pago_o_cobro_id);

    // Si la última fecha de pago es anterior a la fecha actual
    if (fechaUltimoCalculo < fechaActual) {
    var nuevaFecha = new Date(fechaUltimoCalculo);
    var meses = { ‘Mensual’: 1, ‘Bimensual’: 2, ‘Trimestral’: 3, ‘Semestral’: 6, ‘Anual’: 12 };
    var dias = { ‘7 días’: 7 };

    // Añadir tiempo a la fecha según la periodicidad
    if (meses[periodicidadTexto]) {
    nuevaFecha.setMonth(nuevaFecha.getMonth() + meses[periodicidadTexto]);
    } else if (dias[periodicidadTexto]) {
    nuevaFecha.setDate(nuevaFecha.getDate() + dias[periodicidadTexto]);
    }

    // Si la nueva fecha es en el futuro, añadimos una nueva entrada
    if (nuevaFecha > fechaActual) {
    var ultimoImporte = calculos[calculos.length – 1].importes_y_acumulado_id;
    calculos.push({
    fecha_pago_o_cobro_id: nuevaFecha,
    importes_y_acumulado_id: ultimoImporte,
    pagos_y_acumulado_id: ”
    });
    }

    // Actualizamos el campo ‘Pagos y acumulado’ del último cálculo
    calculos[calculos.length – 1].pagos_y_acumulado_id = saldoProximoPagoCobro;

    // Guardamos los cambios en el registro
    registro.setFieldValue(‘fld-d8a58dbf35914f3c858c6dfb880c1c48’, calculos);

    form.saveRecord(registro);
    }
    }
    });

    #50449

    In reply to:

    Fernando DS
    Participant

    Of course the script does not work. It has no errors in the console, but not working.

Viewing 15 results - 16 through 30 (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.