asked on February 4
The code is mostly functional, but I have encountered an issue where date values are not being retrieved correctly until end of function. The dates are stored properly up to the point in code where:
let tableADate = ensureArray(LFForm.getFieldValues({ fieldId: 10 }));
let tableBDate = ensureArray(LFForm.getFieldValues({ fieldId: 11 }));
The next part of the code where the dates are supposed to be stored is encountering an issue, as all the values are empty.
const matchingDates = [];
I am not sure where exactly the issue occurs in the code. Since I am new to coding in Laserfiche, I would appreciate any guidance on identifying and fixing this problem.
// Declare arrays to store matching indexes for various tables
let matchingTableAIndexes = []; // Table A = Table Less/Plus Amounts not on Ledger
let matchingTableBIndexes = []; // Table B = Table Less/Plus Amounts not on Supplier Statement
let matchingTableAAIndexes = [];
let matchingTableDIndexes = []; // Table D = Table Documents Processed on ERP
// Disable fields
LFForm.disableFields({fieldId: 8});
LFForm.hideFields({fieldId: 91});
LFForm.disableFields({fieldId: 33});
// Function to compare Table A and Table B
function tableAandB() {
LFForm.hideFields({ fieldId: 95 });
// Get values from Table A and Table B
let tableAInvoice = ensureArray(LFForm.getFieldValues({ fieldId: 14 })).map(value => value.toUpperCase()); // Convert to Uppercase
let tableBInvoice = ensureArray(LFForm.getFieldValues({ fieldId: 15 })).map(value => value.toUpperCase()); // Convert to Uppercase
let tableAAmount = ensureArray(LFForm.getFieldValues({ fieldId: 18 }));
let tableBAmount = ensureArray(LFForm.getFieldValues({ fieldId: 19 }));
let tableAStatus = ensureArray(LFForm.getFieldValues({ fieldId: 22 }));
let tableBStatus = ensureArray(LFForm.getFieldValues({ fieldId: 23 }));
let tableADate = ensureArray(LFForm.getFieldValues({ fieldId: 10 }));
let tableBDate = ensureArray(LFForm.getFieldValues({ fieldId: 11 }));
LFForm.hideFields({ fieldId: 33 });
// Log initial data from Table A and Table B
console.log('Initial Table A Invoices:', tableAInvoice);
console.log('Initial Table B Invoices:', tableBInvoice);
console.log('Table A Amounts:', tableAAmount);
console.log('Table B Amounts:', tableBAmount);
console.log('Table A Status:', tableAStatus);
console.log('Table B Status:', tableBStatus);
console.log('Table A Dates:', tableADate);
console.log('Table B Dates:', tableBDate);
// Arrays that store different types of values
const matchingData = [];
const authorizedIndexes = [];
const matchingDates = [];
const mismatchedAmounts = [];
// Reset matching indexes
matchingTableAIndexes = [];
matchingTableBIndexes = [];
// Remove "green" and "orange" CSS Class from all fields in each row in Table A and Table B
tableAInvoice.forEach((_, i) => {
LFForm.removeCSSClasses({ fieldId: 10, index: i }, "green orange");
LFForm.removeCSSClasses({ fieldId: 14, index: i }, "green orange");
LFForm.removeCSSClasses({ fieldId: 18, index: i }, "green orange");
LFForm.removeCSSClasses({ fieldId: 22, index: i }, "green orange");
});
tableBInvoice.forEach((_, i) => {
LFForm.removeCSSClasses({ fieldId: 11, index: i }, "green orange");
LFForm.removeCSSClasses({ fieldId: 15, index: i }, "green orange");
LFForm.removeCSSClasses({ fieldId: 19, index: i }, "green orange");
LFForm.removeCSSClasses({ fieldId: 23, index: i }, "green orange");
});
console.log('Processing Table A...');
// Compare each invoice in Table A with Table B
tableAInvoice.forEach((invoiceA, i) => {
const amountA = tableAAmount[i];
const statusA = tableAStatus[i];
const dateA = tableADate[i];
// Skip if data is missing
if (!invoiceA || !amountA || !statusA) {
return;
}
const bIndex = tableBInvoice.findIndex((invoiceB, j) =>
invoiceA === invoiceB && tableBStatus[j]
);
// If a matching invoice is found in Table B
if (bIndex !== -1) {
const statusB = tableBStatus[bIndex];
const dateB = tableBDate[bIndex];
const amountB = tableBAmount[bIndex];
// Log matched invoice details
console.log(`Matching Invoice Found: ${invoiceA}`);
console.log(`Amount A: ${amountA}, Amount B: ${amountB}`);
console.log(`Status A: ${statusA}, Status B: ${statusB}`);
console.log(`Date A: ${tableADate[i]}, Date B: ${dateB}`);
// If both Table A and Table B have 'AUTHORISED' status, mark as authorized
if (statusA === 'AUTHORISED' && statusB === 'AUTHORISED') {
if (amountA === amountB) {
authorizedIndexes.push(i);
matchingData.push({
invoice: invoiceA,
amount: amountA,
status: 'AUTHORISED',
date: dateB
});
matchingDates.push(dateB);
// Apply Green CSS classes to highlight matches
LFForm.addCSSClasses({ fieldId: 10, index: i }, "green");
LFForm.addCSSClasses({ fieldId: 14, index: i }, "green");
LFForm.addCSSClasses({ fieldId: 18, index: i }, "green");
LFForm.addCSSClasses({ fieldId: 22, index: i }, "green");
LFForm.addCSSClasses({ fieldId: 11, index: bIndex }, "green");
LFForm.addCSSClasses({ fieldId: 15, index: bIndex }, "green");
LFForm.addCSSClasses({ fieldId: 19, index: bIndex }, "green");
LFForm.addCSSClasses({ fieldId: 23, index: bIndex }, "green");
matchingTableAIndexes.push(i);
matchingTableBIndexes.push(bIndex);
} else {
mismatchedAmounts.push(i);
// Apply Orange CSS classes to highlight mismatched amounts
LFForm.addCSSClasses({ fieldId: 10, index: i }, "orange");
LFForm.addCSSClasses({ fieldId: 14, index: i }, "orange");
LFForm.addCSSClasses({ fieldId: 18, index: i }, "orange");
LFForm.addCSSClasses({ fieldId: 22, index: i }, "orange");
LFForm.addCSSClasses({ fieldId: 11, index: bIndex }, "orange");
LFForm.addCSSClasses({ fieldId: 15, index: bIndex }, "orange");
LFForm.addCSSClasses({ fieldId: 19, index: bIndex }, "orange");
LFForm.addCSSClasses({ fieldId: 23, index: bIndex }, "orange");
}
}
// Clear the matching values in Table B
tableBInvoice[bIndex] = null;
tableBAmount[bIndex] = null;
tableBStatus[bIndex] = null;
tableBDate[bIndex] = null;
}
});
// Log final results
console.log('Authorized Indexes:', authorizedIndexes);
console.log('Matching Data:', matchingData);
console.log('Matching Dates:', matchingDates);
console.log('Mismatched Amounts:', mismatchedAmounts);
console.log('Final Matching Table A Indexes:', matchingTableAIndexes);
console.log('Final Matching Table B Indexes:', matchingTableBIndexes);
LFForm.showFields({ fieldId: 91 });
LFForm.hideFields({ fieldId: 8 });
populateOtherTable(authorizedIndexes, tableAAmount, tableAStatus, matchingDates); // Populate data in another table
}
0
0