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 - 481 through 495 (of 3,067 total)
  • Author
    Search Results
  • #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();

    Cheers, Daniel

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

    #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.

    #50438
    Simon Spiers
    Participant

    Thanks Daniel. That makes sense and it now works!

    Sam didn’t provide the script, I saw some of it in his video. It seems complex and suited to his own particular use. I’m hoping he’ll weigh in here.

    #50431
    Glen Forister
    Participant

    I made an archive of this Form before I started fixing all the problems so I can show them to you. So far I have identified 2 records that when you look at the archive you should be able to see the behavior working.

    Select Advanced Search = Finished=N
    I think you will find the above mentioned behavior discussed previously on the following records.

    Coleoptera, Aderidae, aderus
    Coleoptera, Bruchidae
    Coleoptera, Curculionidae, Anthonomus
    Coleoptera, Melandryidae, Abdera
    Coleoptera, Phlacridae, 1
    Coleoptera, Scirtidae, Deleted

    Please let me know what you find.  I can’t guarantee the behavior will be seen on all records.

    I wish I could verify this archive, but I can’t do that without replacing the data in my Form.  Maybe I could do that in another Document I think, but not sure.  I stay away from other documents and keep everything in the same document.

    That is one thing I would wish for is a way to copy a form with the data in it and the settings like an archive and create another Form with the archive which has all the work done including the scripts, searches, formatting, etc., just with another name but in the same document.  I often want to create a new document similar to one I’m already using, but don’t want to take the hours or days to do all the work and get it running again like the old one but with a slightly new purpose.

    #50429
    Daniel Leu
    Participant

    I was on the correct track that there’s a type issue. The match() method returns an array. So you can just grab the first element or you might want to additionally check that there’s only one element (found.length ==1):

    record.setFieldValue(mc_id, found[0]);

    Do you have the link to Sam’s parser script? Thanks!

    • This reply was modified 2 years, 3 months ago by Daniel Leu.

    Cheers, Daniel

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

    #50423
    Daniel Leu
    Participant

    Maybe it’s a type issue. Usually Javascript is not very type agnostic. Is MC defined as a number? Does a text field work instead?

    Cheers, Daniel

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

    #50421
    Simon Spiers
    Participant

    Hi Brendan,

    Thanks for the reply and suggestions. Yes, the if statement is to check if the field already has a value and skip the process if so.

    I’ve updated the script but it’s still not populating the form fields:

    function mc() {
    
    var note_id = 'fld-9adb85030f8a42b3aeea043ea5885d05';
    
    var mc_id = 'fld-77a5e9f11f4947caa6135bf312030965';
    
    var input = record.getFieldValue(note_id);
    
    var mcRegex = /[2-6]{1}[0-9]{9}/;
    
    var found = input.match(mcRegex);
    
    if (record.getFieldValue(mc_id) != undefined) {
    
    return;
    
    }
    
    record.setFieldValue(mc_id, found);
    
    document.saveAllChanges();
    
    }
    
    mc();

     

    It seems that the issue is with the record.setFieldValue(mc_id, found); line. I get the correct value if I return found to the console.

    Thanks for looking at it.

    Simon

    • This reply was modified 2 years, 3 months ago by Simon Spiers.
    #50414
    Simon Spiers
    Participant
    I’ve been using Tap Forms for a few years as a digital log book of patients. The primary purpose is to capture billing details. Prompted by watching Sam’s excellent video on OCR Receipt Extraction. I’d like to have a script to auto populate fields with the OCR from a scan of the patient’s ID label.
    .
    My current workflow is to scan a patient’s hospital label with my iPhone, transfer it to the photo field in a new TF record before manually entering data from the scanned image. It’s the digital equivalent of sticking a label in a book in order to annotate it with other data like start and finish times, items, etc.
    .
    What I’d like to do is scan the label with my iPhone (I use Scanner Pro which does a pretty reliable OCR), create a new record in TF that contains the image in a photo field and the OCR’d text in a notes field, then use a form script to automatically populate fields in the TF form. Because the data is sensitive I want to keep it encrypted, only on my own devices and synced using near field only.
    .
    Let me show an example.
    .
    The same fictional patient on different hospital labels gives OCR text:
    .
    HEELER, MR Bandit
    MRN: OT000123456
    DOB: 04/09/1978 Age: 44 (M)
    10 CATTLEDOG ROAD
    BETOOTA HEIGHTS 4483
    Home Ph: 0491 577 426
    MC: 2123456791
    S/Net No:
    DVA:
    BETOOTA PRIVATE
    Adm No
    CT04589023
    Adm Date: 12/01/24
    13:48
    Att Dr: Fixem, Ayecan S
    Ref Dr: Payne, Ophelia M
    Fund: HFHHF
    50006000
    MC Exp: 05/2028 MC Ref: 1
    Pen No:
    0038708Y
    AD: 12/01/2024
    Adm No. 4589023
    HEELER, MR Bandit
    10 Cattledog Rd
    Betoota Heights, QLD 4483
    PH: 0491577426 M: 0491577426
    MC: 2123456791/1 Exp:05/2028
    CL: PI HHF/T 50006000
    PC NIL
    AD: 12/01/2024
    FIXEM, DR AYECAN
    UR: 123456
    Adm No. 4589023
    DOB: 04/09/1978 (44Y)
    MAR: M
    Gender: Male
    BET 0038708Y
    .
    The bits of data I need are first name and surname, DOB, MC, MC Ref, fund code and fund number (‘HHF’ and 50006000 in the example).
    .
    These would map to TF fields surname (text), first name (text), DOB (DD/MM/yyyy), MC (number), MC ref (number), fund code (link from form) and fund number (text; sometimes contains letters) in a single TF form called ‘Cases’.
    .
    The stickers are rectangular and in landscape orientation, so they have information in two columns. The lines of OCR text aren’t always in the same order, e.g. sometimes the admission number or MRN appear between the address lines. The identifier snippets are always present and predictable, though. For instance, fund code is always found after ‘Fund:’ or ‘CL: PI’ which will always be on the same line.
    .
    Sam’s script for his fuel receipts is awesome. I want to do something like it, but I also want to know how it works so I can fix it and build on it. I’m new to scripting and I’m trying to get simple things to work before adding more complexity. Not having much success though. Here’s my attempt:
    .
    function mc() {
    var mc_id = ‘fld-abbabb14632f41718ffb4a259cebe63a’;
    var label_text_id = ‘fld-d80875c6c53048c8bcf97b11e190118d’;
    var input = record.getFieldValue(label_text_id);
    var mcRegex = /[2-6]{1}[0-9]{9}/;
    var found = input.match(mcRegex);
    if (record.getFieldValue(mc_id)) {
    return;
    }
    record.setFieldValue(mc_id, found);
    console.log(found);
    document.saveAllChanges
    }
    mc();
    .
    It finds mc in the notes field text but doesn’t populate the MC field.
    .
    Can anyone help me with this?
    .
    I have a couple of related questions after watching Sam’s video:
    .
    1. How can I create a new record in TF on iOS that contains both the scanned image (jpg) and OCR text string of the scan in a notes field? I’m able to get one piece of information in easily using Shortcuts/x-callback, but two?
    2. How can I create a link from form using scripting? I’d like to extract the fund code (‘HHF’ in the example; Fund:\s?HF?(\D{3})|CL: PI\s?(\D{3})) then link from the HHF record in the ‘Funds’ form.
    #50401
    Glen Forister
    Participant

    I was getting the ID numbers from the right spot, but just using the wrong Script.

    At least I got the one I need to work working, the old one doesn’t want to work, but no time for that and it was primarily there as an example anyhow.

    Thank.

    #50400
    Brendan
    Keymaster

    Hi Christine,

    Have you considered using a Link to Form field between your Collector and Inventory forms? That way a Collector can see a list of their Inventory items and if you look at an individual Inventory item, you can see the collector.

    That might be simpler than writing a script to copy data around from record to record and form to form.

    #50388
    Christine Vernon
    Participant

    Hi!

    I’m trying to figure out if what I want to do is even possible. Javascript is not my thing, but before I seek out someone to help me write the script here’s what I want to do.

    I created two forms:

    • Collectors – records for collector info, each assigned an acct#
    • Inventory – records for individual artworks, each assigned an id#

    Both forms have a table with identical fields for info pertaining to the sale of the artwork. The account # of collector is in the first field.

    If I fill out the table in an Inventory form record, I want the data to automatically populate the table in the individual record of the collector. Essentially creating a table over time of their collection.

    Is it even possible to write a script for the Collector form that would identify the Collector Account # any time it was entered into a table in any of the Inventory form records and automatically copy that information to the corresponding Collector record?

    The data in the table is also used in the Collector form to update other fields to track sales, # of paintings, etc. (which I used formulas to achieve) and why I need all of it to populate over.

    Right now I’d have to copy and paste that set of table data from one record to another. Trying to automate as much as possible but this seems like maybe too big of a task.

    I’ve attached a screenshot of the table.

    Thank you!

    Christine

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

    In reply to: Open record as result

    Scott Specker
    Participant

    Hi Brendan, thanks, this explains why form.selectRecord() wasn’t working on iOS.

    The form.selectRecord() function only works on the Mac version right now.

    You could ask the record for its URL with record.getUrl() and then call Utils.openUrl(url); to have the record displayed on iOS.

    I have a script that creates a new record following your mileage entry example. At the end, I want to go to the newly created record. Since select record doesn’t work on iOS, I tried the URL suggestion.

    Unfortunately, the URL solution doesn’t appear to work on iOS, either. It works on the Mac, but on iOS, it doesn’t jump to the new record. I have to exit the current record and then manually select the new one.

    var newRecord = form.addNewRecord();
    form.saveAllChanges();

    // form.selectRecord(newRecord);
    var url = newRecord.getUrl();
    Utils.openUrl(url);

    Any idea what I am doing wrong?

Viewing 15 results - 481 through 495 (of 3,067 total)