diff --git a/public/js/libProcessScript.js b/public/js/libProcessScript.js index fc33781..3668fae 100644 --- a/public/js/libProcessScript.js +++ b/public/js/libProcessScript.js @@ -77,6 +77,9 @@ async function updatePdfFields( } let ii = 0 dataSource.forEach((record, recIndex) => { + if (ii == 0) { + console.log(JSON.stringify(record, null, 2)) + } console.log(`Processing record[${recIndex}]:`, record); if (!record || typeof record !== 'object') { @@ -85,17 +88,26 @@ async function updatePdfFields( } // Extract numSection and pointValue dynamically or other 'key' components. - const { numSection } = record; - const pointValue = record.pointValue || record.Points; // Fallback to Points if pointValue is missing + /** + * Working area - to wrap assignment of numSection, pointValue or a Key-Value for other datasources. + * so far this is working and success on downloading the PDF prefilled on the score. + */ + const recordToKeyArray = Object.keys(record).includes("$id") + if (recordToKeyArray) { console.log("$ID EXIST") } + const { numSection, pointValue } = record; + const rKey = numSection + const rValue = pointValue + //const pointValue = record.pointValue || record.Points; // Fallback to Points if pointValue is missing + console.log(`[numSection 2 key ==>] ${rKey},${rValue}`) if (numSection && pointValue) { console.log(`Updating PDF field: ${numSection} with value: ${pointValue}`); try { // Use numSection as the dynamic field name - const formField = form.getTextField(numSection); - + //const formField = form.getTextField(numSection); + const formField = form.getFieldMaybe(String(numSection)); // if cannot find, then just returns 'undefined' rather than throw err. if (formField) { ii++ formField.setText(String(pointValue)); @@ -111,6 +123,7 @@ async function updatePdfFields( } }); console.log(`${ii} Form field updates complete.`); + ii = 0; }); diff --git a/public/listFields.html b/public/listFields.html index b5c5240..44ea008 100644 --- a/public/listFields.html +++ b/public/listFields.html @@ -1,19 +1,20 @@ + - - - - PDF Form Fields - + + + + PDF Form Fields + + -

Hardcoded PDF Form Fields

- +

Hardcoded PDF Form Fields

+ - + - + + \ No newline at end of file