Search Results for 'script'
-
Search Results
-
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
- 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.
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 BanditMRN: OT000123456DOB: 04/09/1978 Age: 44 (M)10 CATTLEDOG ROADBETOOTA HEIGHTS 4483Home Ph: 0491 577 426MC: 2123456791S/Net No:DVA:BETOOTA PRIVATEAdm NoCT04589023Adm Date: 12/01/2413:48Att Dr: Fixem, Ayecan SRef Dr: Payne, Ophelia MFund: HFHHF50006000MC Exp: 05/2028 MC Ref: 1Pen No:0038708YAD: 12/01/2024Adm No. 4589023HEELER, MR Bandit10 Cattledog RdBetoota Heights, QLD 4483PH: 0491577426 M: 0491577426MC: 2123456791/1 Exp:05/2028CL: PI HHF/T 50006000PC NILAD: 12/01/2024FIXEM, DR AYECANUR: 123456Adm No. 4589023DOB: 04/09/1978 (44Y)MAR: MGender: MaleBET 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. - Hi everybody,