Hi,
My goal is to create copy and paste like functionality by selecting a checkbox in the table, click a button (thank you for adding button support to the Forms Layout Designer!) to copy selected rows, and add the rows with values to the end of the table. I can get it to add the row(s) with LFForm.addRow but not add the values to the added rows. Seems like it's possible, but I'm not sure where I'm going awry.
Table looks like this, the Total Cost field is calculated
And my js code looks like the following. I've tried a couple iterations with and without adding the LFForms.addRow(), and using the arrays rather than field indexes to fully replace the fields. As written the error "Error: Unable to find field. Please check your ID." shows. Any ideas how to get the duplicated values to go into the new row or if it's possible?
window.duplicateOrder1Rows=function() { var drow=LFForm.getFieldValues({fieldId: 229}); /*Duplicate checkbox, checked value ='V_1'*/ var dqty=LFForm.getFieldValues({fieldId: 206}); var ditmn=LFForm.getFieldValues({fieldId: 207}); var ditmd=LFForm.getFieldValues({fieldId: 208}); var duntc=LFForm.getFieldValues({fieldId: 209}); var dshp=LFForm.getFieldValues({fieldId: 225}); console.log(Array.isArray(drow)); if (Array.isArray(drow)===false){ drow=new Array(drow); } console.log(Array.isArray(dqty)); if (Array.isArray(dqty)===false){ dqty=[dqty]; } dqty=dqty.map(Number); console.log("drow:",drow); console.log("dqty:",dqty); for (var di = 0; di < drow.length; di++) { console.log("drow[",di,"]", drow[di].value); console.log(drow[di].value[0]=='V_1'); if (drow[di].value[0]=='V_1'){ console.log("inside add row value") dqty.push(0); var didx=dqty.length-1; console.log(didx); LFForm.addRow({fieldId: 205}, 1); LFForm.setFieldValues({fieldId: 206, index:didx}, 0); LFForm.setFieldValues({fieldId: 207, index:didx}, ditmn[di]); LFForm.setFieldValues({fieldId: 208, index:didx}, ditmd[di]); LFForm.setFieldValues({fieldId: 209, index:didx}, duntc[di]); LFForm.setFieldValues({fieldId: 225, index:didx}, dshp[di]); } } };
I'm using on prem Laserfiche Forms 11 Update 5 with the Forms Layout Designer.
Possible Enhancements: You can see in the code that there's a couple basic improvements I'd love to see, including table getFieldValues always being in an array, and numbers in number values always being numbers.
Appreciate any help!