Help Setting Field Values from Array Values
Hi all,
I am working on writing a doc-level function to be triggered when a particular page opens.
A salesperson enters information for warranties (up to 4) that a customer has purchased for their vehicle on the first page of the document. When the page for the Bill of Sale opens, I want the "Notes" section to populate with the warranty information (description and cost).
I don't want to take up more of the Notes section than necessary, so the function I'm writing will ultimately shift the line items up/down (i.e. if there is only one warranty package included, I want it to only show up on the last line). I haven't gotten that far yet as I keep getting a "field is null" error when I test this function.
It will work for one line and populate it with information, then error and stop. If I run it a second time, it populates the next line, then errors. I can keep running it and it will fill everything correctly, but I can't figure out where the error is coming from. Any help would be greatly appreciated!
function addWarranty() {
var WarrDesc1 = this.getField("WARR_DESC1").value;
var WarrDesc2 = this.getField("WARR_DESC2").value;
var WarrDesc3 = this.getField("WARR_DESC3").value;
var WarrDesc4 = this.getField("WARR_DESC4").value;
var WarrDescShift1 = this.getField("WARR_DESC_SHIFT1").value;
var WarrDescShift2 = this.getField("WARR_DESC_SHIFT2").value;
var WarrDescShift3 = this.getField("WARR_DESC_SHIFT3").value;
var WarrDescShift4 = this.getField("WARR_DESC_SHIFT4").value;
var WarrRetail1 = this.getField("WARR_RETAIL.0").value;
var WarrRetail2 = this.getField("WARR_RETAIL.1").value;
var WarrRetail3 = this.getField("WARR_RETAIL.2").value;
var WarrRetail4 = this.getField("WARR_RETAIL.3").value;
var WarrRetailShift1 = this.getField("WARR_RETAIL_SHIFT1").value;
var WarrRetailShift2 = this.getField("WARR_RETAIL_SHIFT2").value;
var WarrRetailShift3 = this.getField("WARR_RETAIL_SHIFT3").value;
var WarrRetailShift4 = this.getField("WARR_RETAIL_SHIFT4").value;
var arrWarrDesc = [WarrDesc1, WarrDesc2, WarrDesc3, WarrDesc4];
var arrWarrRetail = [WarrRetail1, WarrRetail2, WarrRetail3, WarrRetail4];
var arrWarrDescShift = [];
var arrWarrRetailShift = [];
for (i = 0; i < arrWarrDesc.length; i++) {
if (arrWarrDesc !== "") {
arrWarrDescShift.push(arrWarrDesc);
arrWarrRetailShift.push(arrWarrRetail);
console.println(arrWarrDescShift + ": " + arrWarrRetailShift);
}
}
for (i = 0; i < arrWarrRetailShift.length; i++) {
this.getField("WARR_DESC_SHIFT" + (i+1)).value = arrWarrDescShift;
this.getField("WARR_RETAIL_SHIFT" + (i+1)).value = arrWarrRetailShift;
}
}
