How To: Add JavaScript event to Line Item Removal/Trashcan

With some custom Javascript the trashcan may effect an update ensuring the resulting remaining items are calculating as intended

Step-by-step guide

  1. Click on Modules.

  2. Select the Module with the Line Item.

  3. Select the Forms tab.

  4. Select Field List button "Create/Update Fields".

  5. Use the filter to find relevant Line Item.

  6. Select the control name or pencil icon to Edit.

  7. Select Custom JavaScript tab.

  8. Paste the Javascript example below in the Init event:

/*** Example: Remove Handler for Line Item trash can **/
fieldScope.factoryremoveRow = fieldScope.removeRow;
fieldScope.removeRow = function (field, idx) {
debugger;
fieldScope.factoryremoveRow(field, idx)
debugger;
var runningTotal = 0;
/ loop for i 0-19 /
for (var i = 0; i < 20; i++) {
/ Using i as row # checks if the field and row exist */
if (formScope.formdata.hasOwnProperty("line_extendedfieldLineItem_customString8_" + i) && formScope.formdata[("line_extendedfieldLineItem_customString8_" + i)]) {
var sysInv = 0;
if (formScope.formdata[("line_extendedfieldLineItem_customNumeric5_" + i)]){
sysInv = formScope.formdata[("line_extendedfieldLineItem_customNumeric5_" + i)];
}
var physInv = 0;
if (formScope.formdata[("line_extendedfieldLineItem_customNumeric6_" + i)]){
physInv = formScope.formdata[("line_extendedfieldLineItem_customNumeric6_" + i)];
}
var pendInv = 0;
if (formScope.formdata[("line_extendedfieldLineItem_customNumeric7_" + i)]){
pendInv = formScope.formdata[("line_extendedfieldLineItem_customNumeric7_" + i)];
}
// Assign total calculation for row
formScope.formdata[("line_extendedfieldLineItem_customNumeric8_" + i)] = (physInv - sysInv);
runningTotal = runningTotal + formScope.formdata[("line_extendedfieldLineItem_customNumeric8_" + i)];
}
}
// Assign Final Total calculation for all rows
formScope.formdata.customNumeric4 = runningTotal;
};

 

9. After refreshing the browser review the resulting form values after selecting the Trash Can icon within a Line Item row.

 

/*** Example: Remove Handler for Line Item trash can **/
fieldScope.factoryremoveRow = fieldScope.removeRow;
fieldScope.removeRow = function (field, idx) {
debugger;
fieldScope.factoryremoveRow(field, idx)
};