All Item translations are accessible using the "translations" sublist of Item record, independently from current user's preferences. Standard Record API and Sublist API functions can be used to retrieve record body fields and line item fields to build a valid XML document, compliant with the BFO Report Generator format. The PDF document is generated from this XML using the nlapiXMLToPDF() function.
Should you need more information on related topics, please take a look at the following articles:
Example 1:
This example shows how to print a PDF document from a Suitelet. The record used for printing is a Sales Order containing items with translations in multiple languages. The resulting PDF contains a simple listing of the items with all available translations.
function suitelet(request, response){ // load a Sales Order first var mySOId = 21449; var mySO = nlapiLoadRecord('salesorder',mySOId); var myLineItemCount = mySO.getLineItemCount('item'); // prepare the header of an BFO XML document var xml = '<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">'; xml += '<pdf onload="javascript:myinit()">'; xml += '<head><meta name="title" value="Sales Order' + mySOId + '"/>'; xml += '<script> <![CDATA[ function myinit() { this.print(); } ]]> </script> '; xml += '</head> <body> ';
xml += '<h1>Sales Order : ' + mySOId + '</h1> '; // load the line items one by one and generate text fields as necessary for (i=1; i<= myLineItemCount; i++) { var myItemId = mySO.getLineItemValue('item', 'item', i); xml += '<b> Item Id: ' + myItemId + '</b> <br/>'; var myItem = nlapiLoadRecord('inventoryitem',myItemId ); // find out how many translations there are for a given item var myItemTransCount = myItem.getLineItemCount('translations'); // generate an entry for each language for (j=1; j<=myItemTransCount ; j++) { var myItemName = myItem.getLineItemValue('translations', 'displayname', j); var myItemLang = myItem.getLineItemValue('translations', 'language', j); xml += '<i> - ' + myItemLang + ' : ' + myItemName + '</i><br/>'; } xml += '<br/>'; } // add the footer of the XML document xml += ' </body> </pdf>'; // generate the PDF document var file = nlapiXMLToPDF( xml ); response.setContentType('PDF','print-me.pdf'); //write the PDF to the Suitelet response.write( file.getValue() );}
No comments:
Post a Comment