HOW TO CREATE A FUNCTIONALITY TO PRINT GL IMPACT OF A TRANSACTION IN NETSUITE?

Netsuite provides the functionality to print a transaction but there is no standard functionality to print GL impact of a transaction. To create a new functionality to print GL impact of a transaction, we can make use of scripts. Using user event script, we can create a custom button on transaction. On click of this button a client script will get triggered which will open a suitelet to print the transaction.

Feel free to reach out netsuite solution providernetsuite implementationnetsuite consultation , netsuite customizationnetsuite Support, netsuite Training  

The code below shows how to create a custom code to print GL impact of an item fulfillment record.

1. First create a client script. This need not be deployed. Note down the script id. Let us assume that script id is “customscript_client_call_suitlet_printgl”.

2. Write a User Event script to add a custom button on item fulfillment. Attach the client script created above to trigger it on click of button.

function userEventBeforeLoad(type, form, request){


if(type==’view’)

{
         form.setScript(‘customscript_client_call_suitlet_printgl’);
         form.addButton(‘custpage_printgl’, ‘PRINT GL’, ‘PRINTGL()’);
}




}

3. Create a suitelet script and note down it’s script id and deployment id.

4. Add the below code to the client script created above to call the newly created suitelet by passing the transaction id.

function PRINTGL(){

var rec_id = nlapiGetRecordId();

var get_suitelet_url = ‘https://system.sandbox.netsuite.com’+nlapiResolveURL(‘SUITELET’, ‘customscriptsuitelet_print_gl’, ‘customdeploy_suitelet_print_gl’);

get_suitelet_url = get_suitelet_url + ‘&rec_id=’+rec_id;

window.open(get_suitelet_url);


 
}

5. Add the below code to the suitelet script created above to print the GL impact.  This script creates a template to print the GL impact and searches all the values required to be shown in the print layout and then adds those values in the templates.

// Read the gl impact and create a pdf layout for it.
function suitelet_printgl(request, response){

var rec_id = request.getParameter(‘rec_id’);

var item_fulfillment = nlapiLoadRecord(‘itemfulfillment’, rec_id); // Load employee record by ID

    var renderer = nlapiCreateTemplateRenderer(); 
    var template = ‘<?xml version=”1.0″?><!DOCTYPE pdf PUBLIC “-//big.faceless.org//report” “report-1.1.dtd”>’;
    template = template +'<pdf>’;
    template = template + ‘<head>’;
   
    template = template + ‘ <style>’;
    template = template + ‘ table, th, td {‘;
    template = template + ‘border: 1px solid black;’;
    template = template + ‘ }’;
    template = template + ‘ table{‘;
    template = template + ‘width: 1400px;height:500px’;
    template = template + ‘ }’;
    template = template + ‘</style>’;
    template = template + ‘</head>’;
    template = template + ‘<body width=”2500px”>’;
 
    template = template + ‘ <table>’;
   
    template = template + ‘ <tr>’;
   
    template = template + ‘ <th>ACCOUNT</th>’;
    template = template + ‘ <th>AMOUNT (DEBIT)</th>’;
    template = template + ‘ <th>AMOUNT (CREDIT)</th>’;
    template = template + ‘ <th>POSTING</th>’;
    template = template + ‘ <th>MEMO</th>’;
    template = template + ‘ <th>NAME</th>’;
    template = template + ‘ <th>SUBSIDIARY</th>’;
    template = template + ‘ <th>DEPARTMENT</th>’;
    template = template + ‘ <th>LOCATION</th>’;
   
    template = template + ‘</tr>’;
   
    var filters = new Array();
    var columns = new Array();
    filters[0] = new nlobjSearchFilter(‘internalid’, null, ‘anyof’, rec_id);
   

    columns[0] = new nlobjSearchColumn(‘account’);
    columns[1] = new nlobjSearchColumn(‘debitamount’);
    columns[2] = new nlobjSearchColumn(‘creditamount’);
    columns[3] = new nlobjSearchColumn(‘posting’);
    columns[4] = new nlobjSearchColumn(‘memo’);
    columns[5] = new nlobjSearchColumn(‘entity’);
    columns[6] = new nlobjSearchColumn(‘subsidiary’);
    columns[7] = new nlobjSearchColumn(‘department’);
    columns[8] = new nlobjSearchColumn(‘location’);
    columns[9] = new nlobjSearchColumn(‘exchangerate’);

   
    var gl_Record = nlapiSearchRecord(‘transaction’, null, filters, columns);
   
    for ( var i = 0; i < gl_Record.length; i++) {
   
    if(gl_Record[i].getText(columns[0])!=null&&gl_Record[i].getText(columns[0])!=”&&gl_Record[i].getText(columns[0])!=’ ‘)
    {
   
    template = template + ‘  <tr>’;
   
    template = template + ‘ <td>’+gl_Record[i].getText(columns[0])+'</td>’;
        //use getText to get the text value of a select type field or a field that has both the

    template = template + ‘ <td>’+gl_Record[i].getValue(columns[1])+'</td>’;
    template = template + ‘ <td>’+gl_Record[i].getValue(columns[2])+'</td>’;
    template = template + ‘ <td>’+gl_Record[i].getValue(columns[3])+'</td>’;
    template = template + ‘ <td>’+gl_Record[i].getValue(columns[4])+'</td>’;
    template = template + ‘ <td>’+gl_Record[i].getText(columns[5])+'</td>’;
    template = template + ‘ <td>’+gl_Record[i].getText(columns[6])+'</td>’;
    template = template + ‘ <td>’+gl_Record[i].getText(columns[7])+'</td>’;
    template = template + ‘ <td>’+gl_Record[i].getText(columns[8])+'</td>’;
   
   
    nlapiLogExecution(‘DEBUG’, ‘fxamount/’, parseFloat(gl_Record[i].getValue(columns[1])).toFixed(2)/parseFloat(gl_Record[i].getValue(columns[9])).toFixed(2));
     
    template = template + ‘</tr>’;
    }
   }
 
   
    template = template + ‘ </table>’;
    template = template + ‘    </body>’;
    template = template + ‘ </pdf>’;
     
    renderer.setTemplate(template); // Passes in raw string of template to be transformed by FreeMarker
    renderer.addRecord(‘itemfulfillment’, item_fulfillment);
    var xml = renderer.renderToString(); // Returns template content interpreted by FreeMarker as XML string that can be passed to the nlapiXMLToPDF function.
    var file = nlapiXMLToPDF(xml); // Produces PDF output.
    response.setContentType(‘PDF’, ‘GL IMPACT.pdf’, ‘inline’);
    response.write(file);

}


Leave a Reply