Hi,
I was wondering if anybody would be kind enough to QA my code here and see why I might be getting errors. I've tried to use debugging to get more info on where it might be going wrong to no avail so far. The pivot report page generates but I just get an error "NetSuite has encountered an error while generating your report." The code will eventually be a little more complex as I need to take out some of the fixed values and turn them in to custom parameters, but for now I'm just trying to get the pivot report to work. I suspect it has to do with how I've defined some of my filters and columns, if anyone has experience doing this and any insight in to potential problems that would be great.
function customerProfitAndLoss(request,response)
{
if (request.getMethod() == 'GET' )
{
//Create the form and add fields to it
var form = nlapiCreateForm("Generate Customer Profit and Loss Report" );
form.addSubmitButton('Submit' );
response.writePage(form);
}
else
{
var reportDefinition = nlapiCreateReportDefinition();
var accountType = reportDefinition.addRowHierarchy('accounttype','Account Type','TEXT');
var date = reportDefinition.addColumnHierarchy('date','Month',null,'DATE');
var amount = reportDefinition.addColumn('amount',false,'Amount',date,'CURRENCY',null);
//build search
var columns = new Array();
columns[0] = new nlobjSearchColumn('accounttype', null, 'group');
columns[1] = new nlobjSearchColumn('account',null,'group');
columns[2] = new nlobjSearchColumn('date',null,'group').setFunction('month');
columns[3] = new nlobjSearchColumn('amount',null,'sum');
var filters = new Array();
filters[0] = new nlobjSearchFilter('accounttype',null,'anyof',['Income','Cost of Goods Sold','Expense','Other Income','Other Expense'],null);
filters[1] = new nlobjSearchFilter('postingperiod',null,'within','lastfiscalyear',null);
filters[2] = new nlobjSearchFilter('mainline',null,'is','F',null);
filters[3] = new nlobjSearchFilter('posting',null,'is','T',null);
//stand in filter - make this dynamic
filters[4] = new nlobjSearchFilter('custbody_reporting_purposes',null,'anyof','Myer');
reportDefinition.addSearchDataSource('transaction',null,filters,columns,{'accounttype':columns[0],'account':columns[1],'date':columns[2],'amount':columns[3]});
var form = nlapiCreateReportForm('Pivot Report Suitelet : Customer Profit and Loss');
var pvtTable = reportDefinition.executeReport(form);
response.writePage(form);
}
}