This topic contains 4 replies, has 0 voices, and was last updated by Jordan Manningham 7 years, 9 months ago.
-
AuthorPosts
-
January 23, 2017 at 10:15 am #2267
Jordan ManninghamThis is the first time I’ve had to learn XML and build a pdf with it. I’m not entirely sure what is wrong with my code. On the click of a button, a pdf should be generated, though I’m currently getting and unexpected error. I’m hoping someone can point out obvious mistakes or advise where to go from here. I’ve commented out many of the other fields that will be on the PDF so I can test with a few fields at a time. If I could get the error to disappear, I think I’ll be able to slowly piece it all together.
Code:
// This is called from the client script tied to the “Print PEF” button on the item recordfunction demoSimpleForm(request, response, recordid) // On button click
{
if ( request.getMethod() == ‘GET’ )
{
// Loads search to find recent PEF requests
var loadSearch = nlapiLoadSearch(‘customrecord139’, ‘customsearch710’);
var getData = loadSearch.runSearch();
var all_results = getData.getResults(0, 1);
var all_col = all_results[0].getAllColumns();
var o_id = all_results[0].getValue(‘custrecord196’);
var o_rt = all_results[0].getValue(‘custrecord197’);var o_r = nlapiLoadRecord(o_rt, o_id); // Loads the correct item record
var item = o_r.getFieldValue(‘itemid’);
var item_name = o_r.getFieldValue(‘displayname’);// The below variables are all the field labels and field values needed to be put on the PDF
var main_date_prepared = o_r.getField(‘custitem15’).getLabel();
var main_revision_number_v = o_r.getFieldValue(‘custitem_pef_number’);var xml = ‘‘
xml += ‘‘
xml += ‘‘
xml += ‘‘
xml += ‘‘
xml += ‘‘
xml += ‘‘
/**xml += ‘‘
xml += ‘‘
xml += ‘‘
xml += item_name //+ ‘
‘// + ‘Product Engineering Form (PEF) for item ‘ + item + ‘ generated on ‘ + new Date() + ‘‘
‘
xml += ‘
xml += ‘‘
xml += ‘‘**/
xml += ‘‘
xml += ‘‘
xml += ‘Main’
xml += ‘‘
xml += ‘‘
xml += ‘‘
xml += ‘‘ + main_date_prepared + ‘ ‘
xml += ‘‘ + main_date_prepared_v + ‘ ‘
xml += ‘‘
xml += ‘‘
xml += ‘‘
xml += ‘‘
/**xml += ‘‘**/
‘
xml += ‘‘
xml += ‘
xml += ‘‘
xml += ‘‘response.renderPDF(xml); //TESTING WITH ITEM 6700-55
}
else{
dumpResponse(request,response);
}}
This is a cached copy. Click here to see the original post. -
January 23, 2017 at 3:27 pm #2268
michoelJavaScript is case sensitive, you should be using “renderPdf” not renderPDF
https://system.netsuite.com/app/help…426014776.html
-
January 24, 2017 at 10:16 am #2269
wwintersI usually put my XML to PDF rendering in a try/catch block :
Code:
try {
var file = nlapiXMLToPDF(html);
response.setContentType(‘PDF’, ‘Print.pdf ‘,’inline’);
response.write(file.getValue());
}
catch (e) {
html = e + html;
response.write(html);
} -
February 17, 2017 at 9:14 am #2270
JohnCColeHave you tried putting content in the body. Your example is putting together a header with no content in the body, I think this could be the cause for the expected error.
Try
Code:
xml += ‘Testing PDF’ -
February 17, 2017 at 9:27 am #2271
Jordan ManninghamI got this to work by creating a string in the javascript part of my script using a basic for loop. Then I plugged the string into the xml and it worked like a charm.
Code:
//Components – Bill of Materials
var lines = o_r.getLineItemCount(‘member’);
var bom_string;
for (var mem = 1; mem <= lines; mem++){
components[mem – 1][0] = o_r.getLineItemText('member', 'item', mem);
components[mem – 1][1] = o_r.getLineItemValue('member', 'memberdescr', mem);
components[mem – 1][2] = o_r.getLineItemValue('member', 'quantity', mem);
components[mem – 1][3] = o_r.getLineItemValue('member', 'memberunit', mem);
bom_string += '‘ + components[mem – 1][0] + ‘ ‘ + components[mem – 1][1] +
‘‘ +components[mem – 1][2] + ‘ ‘ + components[mem – 1][3] + ‘ ‘;
}while (bom_string.indexOf(‘ & ‘) != -1){
bom_string = bom_string.replace(‘ & ‘, ‘ & ‘);
}while (bom_string.indexOf(‘null’) != -1){
bom_string = bom_string.replace(‘null’, ‘ ‘);
} -
AuthorPosts
You must be logged in to reply to this topic.