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

Created by Joshua Miller, Modified on Tue, 25 Mar at 5:59 PM by Joshua Miller

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)
};

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article