Hi all,
I am stumped. I have a Suitelet that runs a saved search, we process the results and then display info. IT has been working for months but suddenly it is producing an error.
Here is part of the code
salesSearch.run().each(function(result) {
log.debug({title: 'result', details: result});
var moyr = result.getValue({name: 'trandate', summary: 'GROUP'});
var qty = result.getValue({name: 'quantity', summary: 'SUM'});
var amt = result.getValue({name: 'amount', summary: 'SUM'});
var strAmt = format.format({ value: amt, type: format.Type.CURRENCY });
var cost = result.getValue({name: 'costestimate', summary: 'SUM'});
var strCost = format.format({ value: cost, type: format.Type.CURRENCY });
var profit = result.getValue({name: 'estgrossprofit', summary: 'SUM'});
var strProfit = format.format({ value: profit, type: format.Type.CURRENCY });
var avgcost = result.getValue({name: 'costestimaterate', summary: 'AVG'});
var strAvgCost = format.format({ value: avgcost, type: format.Type.CURRENCY });
var PMPcnt = ( parseFloat(profit) / parseFloat(amt) ) * 100;
var strPMPcnt = format.format({ value: PMPcnt.toFixed(2), type: format.Type.PERCENT });
log.debug({title: 'moyr', details: moyr});
log.debug({title: 'qty', details: qty});
if (moyr.substring(0,4) != prevmoyr.substring(0,4) && prevmoyr != '')
{
it is erroring on this last if statement
org.mozilla.javascript.EcmaError: TypeError: Cannot call method "substring" of null (/SuiteScripts/PE Scripts 2.0/pe2_sl_itesmsaleshistory.js#122)
the debug output shows there is a value for trandate in the search but the var moyr is blank and I have no idea why
| | Debug | moyr | | | | |
| | | result | | | | {"values":{"GROUP(trandate)":"2017-10","SUM(quantity)":"182","SUM(amount)":"4496.72","SUM(costestimate)":"2169.44","SUM(estgrossprofit)":"2327.28","AVG(costestimaterate)":"11.92","AVG(rate)":"24.91"}} | |
| | Debug | {"details":{"name":"rate","summary":"AVG","label":"Avg Price","type":"currency2","function":"roundT | | | | | |
| | Debug | {"details":{"name":"costestimaterate","summary":"AVG","label":"Avg Cost","type":"currency","sortdir | | | | | |
| | Debug | {"details":{"name":"estgrossprofit","summary":"SUM","label":"Profit $","type":"currency","sortdir": | | | | | |
| | Debug | {"details":{"name":"costestimate","summary":"SUM","label":"Total Cost","type":"currency","sortdir": | | | | | |
| | Debug | {"details":{"name":"amount","summary":"SUM","label":"Sales Dollars","type":"currency","sortdir":"NO | | | | | |
| | Debug | {"details":{"name":"quantity","summary":"SUM","label":"Qty Sold","type":"float","sortdir":"NONE"}} | | | | | |
| | Debug | {"details":{"name":"trandate","summary":"GROUP","label":"Yr-Mo","type":"date","function":"month","s | | | | |