Use Case: To sort rows in a User Report by more than just one field.
The bottom half of this script is completely generic, and can be used on any User Report in Infoplus (everything from the // copy the rows comment to the bottom). The compare function at the top of the script can be customized to look at whatever fields you want to sort by (adding more fields, or using whatever field names you need). Be careful that you may need to deal with missing value (possibly represented as "--" in the report).
////////////////////////////////////////////////////////////////////////////// // custom compare function - takes 2 report rows as input // returns -1 if a comes before b, 1 if a comes after b, or 0 if they tie. // ////////////////////////////////////////////////////////////////////////////// function compare(a, b) { ///////////////////////////////////////////////////////////////////////////// // get first field value - if they differ, return -1 or 1 - else continue. // ///////////////////////////////////////////////////////////////////////////// var skuA = a.get("SKU"); var skuB = b.get("SKU"); if(skuA < skuB) { return(-1); } else if(skuA > skuB) { return(1); } //////////////////////////////////////////////////////////////////////////// // get next field value - if they differ, return -1 or 1 - else continue. // //////////////////////////////////////////////////////////////////////////// var receivedDateA = new Date(a.get("Received Date")); var receivedDateB = new Date(b.get("Received Date")); if(receivedDateA < receivedDateB) { return(-1); } else if(receivedDateA > receivedDateB) { return(1); } ///////////////////////////////////////////// // at this point, they're a tie - return 0 // ///////////////////////////////////////////// return(0); } /////////////////////////////////////////// // copy the rows into a javascript array // /////////////////////////////////////////// var rows = []; for(var i=0; i<report.originalRows.size(); i++) { rows.push(report.originalRows.get(i)); } ///////////////////////////////////////////////// // sort that array, using our compare function // ///////////////////////////////////////////////// rows.sort(compare); /////////////////////////////////////// // put the sorted rows in the report // /////////////////////////////////////// for(var i=0; i<rows.length; i++) { report.addRow(rows[i]); }