In NetSuite you can generate the pdf, along with that you can also add form elements in your document like text box, drop-down list, and radio buttons to make your pdf more interactive. Also you can run JavaScript’s on your generated pdf.
Here in this tip you would come to know how to run it.
1. Create a suitelet in which you will generate pdf and run JavaScript usingnlapiXMLToPDF using the following code..
function RunJavaScript (request, response) { try { //Create the xml var xml = ""; xml += ""; //Add the head and body part to it xml += ""; xml += ""; xml += ""; xml += "\n"; // convert the xml document to a PDF(fileobj) var file = nlapiXMLToPDF(xml); //generate a file response.setContentType('PDF', 'javascript.pdf ', 'inline'); // write response to the client response.write(file.getValue()); } catch (ex) { nlapiLogExecution('DEBUG', 'error', ex); } }
2. Add the form elements like text box, radio buttons that are to be inserted in pdf in xml, add them in tag which was added above. Here I have added two fields one is of type ‘text’ and other is of ’radio’ button type.
//Add to the table the required fields var strName = "
“; //Add the name field strName += “”; strName += “”; strName += “”; //add the gender field strName += “”; strName += “”; strName += “”; //Add it to the body xml += “”; Here it is getting added to xml part inside the tag same as we use to do in HTML. xml += strName; xml += ”
Name | |
Sex | “; strName += “Male “; strName += “Female “; strName += “ |
“; xml += “\n”;
The key things to remember is that the “name” and “type” values are mandatory and each name must be unique across the entire document i.e. the pdf.
3. Now add the JavaScript in the xml tag. Same as use to do in HTML but use “CData” block instead of < and > characters in which JavaScript code is written.
//Add the script in head xml += ""; xml += ""; xml += ""; xml += ""; xml += "";
To run this JavaScript add the button name” submit” in the tag. On click of that button assign the JavaScript function (javascript:RunScript()) .
xml += “”;
On the button click the JavaScript function named “RunScript” would run which will show alert message.