Sunday, February 17, 2019

Execute Different Pivot Charts from a Suitelet

Concern:
How to create different Pivot Chart Reports based on the selected Transaction Type from the Suitelet?

(1) Select Record Type to be Used in Creating a Report (ex. Sales Order Report)



(2) Click Submit Button. It should generate this Report


 

Solution:

GET Method

(1) Create a form that will consist of the transaction types.
(2) Add field that will handle the list of transaction types.
(3) Create a Submit button that will direct to the Pivot Report created based on the selected transaction type.
if(request.getMethod() == 'GET')
{
   var form = nlapiCreateForm("Detailed Transactions Accounting Report");
   var type= form.addField("type1","select","Type",'transactiontype');

   form.addSubmitButton('Submit');
   response.writePage(form);
}


POST Method
(1) Get type selected by the customer.
(2) Create Report Definition, add columns and hierarchy.
(3) Execute the Search by calling addSearchDataSource.

    var type_val = (request.getParameter("type1") == null) ? "": request.getParameter("type1");

(4) getParameter returns internal id (number) of the selected value and addSearchDataSource expects the internal id of the record type, we need to add a condition that will set internal id (number) to internal id.

// 37 is the internal id (number) of Sales Order
    if(type_val == '37'){
         var setType = 'salesorder';
    }

   reportDefinition.addSearchDataSource(setType, null, filters, columns,
    {'internalID':columns[0], 'entity':columns[1], 'salesrep':columns[2], 'expectedclosedate':columns[3],
     'entitystatus':columns[4], 'projectedtotal':columns[5], 'probability':columns[6]});
   
(5) Create a form to build the report on
      var form = nlapiCreateReportForm('Pivot Report Suitelet: Opportunities');     
   
(6) Build the form from the report definition
    var pvtTable = reportDefinition.executeReport(form); 
   
(7) Write the form to the browser
    response.writePage(form);

Notes:
For the list of Transaction Type Internal ID (number) to be used, you may search for  Transaction Type Internal ID (number).

No comments:

Post a Comment