I’m trying to build a table in a script, and am having trouble getting it to work exactly as I want it to, and I’m not certain what I’m doing wrong. I’m trying to display invoice items, and the number of rows per item is conditional.
I’ve played around with the last line of the script, .html versus .after. (.after) formats my lines correctly, but messes up paging, while (.html) pages correctly but doesn’t include the tags for any row after the first one in each item.
Can you help me with the correct/best way to do this?
Table:
Line
Item#/PO/Description
Ordered
Shipped
Unit Price
Ext. Price
Script using Selector: #Items tbody tr
results.each(function(index) {
var result = “”;
var thisItem = record.tables.InvoiceItem[index];
var cls = “”;
var format = new TextFormatter(locale);
if (thisItem != null){
if (index % 2 == 0){cls = "odd"; query("#firstrow").attr("class","odd");}
else {cls = "even"; query("#firstrow").attr("class","even");}
var custItem = thisItem.fields["custItem"];
var item = thisItem.fields["item"];
var lineItem;
var secondLineItem = "";
if (custItem == "" || custItem == item)
{
lineItem = item ;
}
else
{
lineItem = "C/I: " + custItem;
secondLineItem = item;
}
//Add the unit of measure to the first item line
lineItem = lineItem + ' U/M: ' + thisItem.fields["UOM"] + '&nbsp&nbsp&nbsp';
//.toFixed(2).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, “$1,”)
var extPrice = format.currency(thisItem.fields[“Price”] * thisItem.fields[“QtyShipped”]);
var qtyOrdered = format.grouped(thisItem.fields[“QtyOrdered”]);
var qtyShipped = format.grouped(thisItem.fields[“QtyShipped”]);
var extTotal = extTotal + extPrice;
//This is the first row, item or cust item, U/M, and ordered/shipped/prices
result += '';
result += '' + thisItem.fields["lineNum"] + '';
result += '' + lineItem + '';
result += '' + qtyOrdered + '';
result += '' + qtyShipped + '';
result += '' + thisItem.fields["Price"] + '';
result += '' + extPrice + '';
result += '';
//This is the second row, item if necessary, description
result += '';
result += '';
result += '';
if (secondLineItem != ""){ result += secondLineItem + "&nbsp&nbsp-&nbsp&nbsp";}
result += thisItem.fields["itemDescription"] + '';
result += '';
//Then if necessary, the cust PO, HTS, revision go here
if (thisItem.fields["CustPO"] != "" || thisItem.fields["HTSCode"] != "" || thisItem.fields["Revision"])
{
result += '';
result += '';
result += '';
if (thisItem.fields["Revision"] != ""){result += ' Rev:' + thisItem.fields["Revision"];}
if (thisItem.fields["CustPO"] != ""){result += ' ' + thisItem.fields["CustPO"];}
if (thisItem.fields["HTSCode"] != ""){result += ' HTS:' + thisItem.fields["HTSCode"];}
result += '';
}
//Finally loop through the line notes, if there are any, and create a new line for each
if(thisItem.tables.LineNotes != null) {
var Notes = thisItem.tables.LineNotes;
var noteslen = Notes.length;
//Loop through as many notes as there are
for (var n=0;n';
result += ''; //This is the first column - blank
result += '' + thisNote.fields["Notes"];
result += '';
}
}
}
result += '';
result += ' ';
this.html(result);
});