Search Results for 'form.getRecords'
-
Search Results
-
Hello everyone, I have an amount search script in the table field of all records. But it works for me with some quantities and not with others. And I don’t understand why.
This is the script:// Definiciones de IDs de campos dentro de la tabla
var pagos_cobros_tabla_id = ‘fld-a878bb1af5534101bcfab905279b1180’; // ID del campo Pagos/Cobros dentro de la tabla
var movs_banco_tabla_id = ‘fld-57a5fdcd593e46b298948845321d78ac’; // ID del campo Mvtos. Banco dentro de la tabla
var fecha_id = ‘fld-547c13e982e84d0793b0aba6c220cf76’; // ID del campo de fecha dentro de la tabla
var nombre_id = ‘fld-baf116cd116e4cde9b65e79014a49f28’; // ID del campo de nombre dentro de la tabla
var tabla_id = ‘fld-d8a58dbf35914f3c858c6dfb880c1c48’;
var nota_id = ‘fld-7918261f865b489a8f7672cf733712a9’;
var listado_de_script_id = ‘fld-555622f4bf0344f9b9e92af0806210fc’;
// Reemplazar ‘XXXXXX’ con el ID del campo “Listado de script”// Define el importe a buscar
var buscarImporte = “19.99”; // Ajusta este valor según el importe que desees buscarconsole.log(“”);
console.log(“*************************************”);
console.log(“Importe buscado: ” + buscarImporte);
console.log(“*************************************”);
console.log(“”);// Inicializar el contenido del campo “Listado de script”
var output = “”;// Función para parsear el importe independientemente del formato
function parseImporte(importeStr) {
if (typeof importeStr === ‘string’) {
return parseFloat(importeStr.replace(/[^\d.-]/g, ”)) || 0; // Devolver 0 si el valor no se puede convertir a número
} else {
return parseFloat(importeStr) || 0; // Devolver 0 si el valor no se puede convertir a número
}
}buscarImporte = parseImporte(buscarImporte);
var records = form.getRecords();
for (var i = 0; i < records.length; i++) {
var record = records;
var registrosTabla = record.getFieldValue(‘fld-d8a58dbf35914f3c858c6dfb880c1c48’) || []; // Reemplaza ‘tabla_id’ con el ID del campo de la tabla
var nombre = record.getFieldValue(‘fld-baf116cd116e4cde9b65e79014a49f28’); // Obtener el nombre fuera del bucle de la tabla// Array para almacenar los movimientos correspondientes a cada nombre
var movimientosNombre = [];for (var j = 0; j < registrosTabla.length; j++) {
var registroTabla = registrosTabla[j];
var pagosCobros = parseImporte(registroTabla.getFieldValue(pagos_cobros_tabla_id));
var movsBanco = parseImporte(registroTabla.getFieldValue(movs_banco_tabla_id));
var fechaRaw = new Date(registroTabla.getFieldValue(fecha_id));
var fecha =${('0' + fechaRaw.getDate()).slice(-2)}/${('0' + (fechaRaw.getMonth() + 1)).slice(-2)}/${fechaRaw.getFullYear().toString().substr(-2)}
;
var nota = registroTabla.getFieldValue(nota_id);// Comparar el valor absoluto de los importes
if (Math.abs(pagosCobros) === Math.abs(buscarImporte) || Math.abs(movsBanco) === Math.abs(buscarImporte)) {
movimientosNombre.push({ fecha: fecha, movsBanco: movsBanco, pagosCobros: pagosCobros, nota: nota });
}
}// Mostrar el nombre y luego los movimientos correspondientes
if (movimientosNombre.length > 0) {
output += “\n” + nombre + “\n\n”;
console.log(“” + nombre);
console.log(“”);
for (var k = 0; k < movimientosNombre.length; k++) {
var movimiento = movimientosNombre[k];
output +=${movimiento.fecha}: ${movimiento.movsBanco} | ${movimiento.pagosCobros}\n\n${movimiento.nota}\n
;
console.log(${movimiento.fecha}: ${movimiento.movsBanco} | ${movimiento.pagosCobros}
);
console.log(“” + movimiento.nota);
console.log(“”);
}
}
}// Actualizar el campo “Listado de script” del primer registro con el texto generado
record.setFieldValue(listado_de_script_id, output);// Guardar los cambios en los registros
form.saveAllChanges();Any help will be welcome.
Topic: Previous record skip
I can’t figure out how to fix the code so the first actual record after the “Begin Year Mark” record adds the $100 to $0 of the initialization record for the year.Thanks…Date Org $ Total$01/01/24 Begin. 0 0 Begin Year mark01/01/24. KVMR 100 003/12/24 test 20 2003/27/24. test.2. 50 7004/17/24. test.3. 55 125Can’t remember how to display the code correctly – searched for it – Put that hint somewhere? “!”???!function Year_to_date() {var date_id = ‘fld-e2d20da877cb4a6c8fd72153b86f1ab1’;var donation_id = ‘fld-05c429d6a4484061b554aa584a45f8fc’;var total_id = ‘fld-7c6b9bb288ab47e0b295af6eacc9cd26’;var records = form.getRecords(); // calls function getRecords()var currentRecordIndex = records.indexOf(record);if (currentRecordIndex > 0) {var previousRecord = records[currentRecordIndex-1];} else {return 0;}// Is this the beginning of the year?var date = record.getFieldValue(date_id);if (date.getMonth() == 0 && date.getDate() == 1){return 0;}var today = record.getFieldValue(donation_id);var previous_total = previousRecord.getFieldValue(total_id);var total = today + previous_total;console.log(“Today: ” + today)console.log(“Previous: ” + previous_total)console.log(“Total: ” + total)return total;}Year_to_date();!- 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.
- Hi everybody,