erictgrubaugh
10/06/2017, 4:21 PMerictgrubaugh
10/06/2017, 4:53 PM/**
* Retrieves the Sales Rep with the largest (by Total)
* Sales Order in each Period
*
* @author Eric T Grubaugh <eric@stoic.software>
*/
require(["N/search"], function (s) {
s.create({
type: s.Type.SALES_ORDER,
filters: [
["mainline", <http://s.Operator.IS|s.Operator.IS>, true], "and",
["salesrep", s.Operator.NONEOF, "@NONE@"]
],
columns: [
{name: "postingperiod", summary: s.Summary.GROUP},
s.createColumn({
name: "salesrep",
summary: s.Summary.MAX
}).setWhenOrderedBy({name:"totalamount", join: "x"})
]
}).run().getRange({start: 0, end: 10}).forEach(printOrder);
function printOrder(result) {
console.log(
result.getValue({name:"salesrep", summary:s.Summary.MAX}) +
" had the largest order in " +
result.getText({name:"postingperiod", summary:s.Summary.GROUP})
);
return true;
}
});
erictgrubaugh
10/06/2017, 4:54 PMerictgrubaugh
10/06/2017, 5:00 PMerictgrubaugh
10/06/2017, 5:04 PMerictgrubaugh
10/06/2017, 5:13 PM/**
* Retrieves the Contact on the most recent Case filed
* by each Customer
*
* @author Eric T Grubaugh <eric@stoic.software>
*/
require(["N/search"], function (s) {
s.create({
type: s.Type.SUPPORT_CASE,
filters: [["contact", s.Operator.ISNOTEMPTY, ""]],
columns: [
{name: "company", summary: s.Summary.GROUP},
s.createColumn({
name: "contact",
summary: s.Summary.MAX
}).setWhenOrderedBy({name:"createddate", join: "x"})
]
}).run().getRange({start: 0, end: 10}).forEach(printOrder);
function printOrder(result) {
console.log(
result.getValue({name:"contact", summary:s.Summary.MAX}) +
" is the Contact on " +
result.getValue({name:"company", summary:s.Summary.GROUP}) +
"'s most recent Case."
);
return true;
}
});
erictgrubaugh
10/06/2017, 5:14 PMerictgrubaugh
10/06/2017, 5:37 PM