This topic contains 4 replies, has 0 voices, and was last updated by Jordan Manningham 7 years, 2 months ago.

  • Author
    Posts
  • #2267 Score: 0

    Jordan Manningham
    • Contributions: 0
    • Level 1

    This 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 record

    function 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 version="1.0"?>‘
    xml += ‘< !DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">‘
    xml += ‘
    xml += ‘‘
    xml += ‘
    xml += ‘
    xml += ‘


    /**xml += ‘


    xml += ‘


    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 += ‘Main’
    xml += ‘
    ‘ + main_date_prepared + ‘ ‘ + main_date_prepared_v + ‘


    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.

  • #2268 Score: 0

    michoel
    • Contributions: 0
    • Level 1

    JavaScript is case sensitive, you should be using “renderPdf” not renderPDF

    https://system.netsuite.com/app/help…426014776.html

  • #2269 Score: 0

    wwinters
    • Contributions: 0
    • Level 1

    I 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);
    }

  • #2270 Score: 0

    JohnCCole
    • Contributions: 0
    • Level 1

    Have 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’

  • #2271 Score: 0

    Jordan Manningham
    • Contributions: 0
    • Level 1

    I 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’, ‘ ‘);
    }

You must be logged in to reply to this topic.