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

  • Author
    Posts
  • #21912 Score: 0

    Jordan Manningham
    • Contributions: 0
    • Level 1

    Hi All,

    I've been working on a project that requires generating a PDF which of course requires some knowledge of HTML and CSS. The part I'm stuck on requires some JavaScript though I'm not sure how to tie both languages together using <script> tags. The intended purpose of this portion of the script is to create a table with X amount of rows where X is the number of members./components that an item record has. I've been trying practically everything that any relevant resource says but still no luck. Right now the script produces an error (TypeError: <script type="text/javascript"> is not a function, it is string. (pef_to_pdf.js$262376#199))

    The part that screws me up is document.getElementById. Every resource I've found indicates some use of it for this purpose. Is this the right function to use and is my <script> in the right place? This is my first attempt at HTML/CSS.

    Code:
    var line1 = [];
    var line2 = [];
    var line3 = [];
    var line4 = [];
    var line5 = [];
    var line6 = [];
    var line7 = [];
    var line8 = [];
    var line9 = [];
    var line10 = [];
    var line11 = [];
    var line12 = [];
    var line13 = [];
    var line14 = [];
    var line15 = [];
    var line16 = [];
    var line17 = [];
    var line18 = [];
    var line19 = [];
    var line20 = [];

    var components = [line1, line2, line3, line4, line5, line6, line7, line8, line9, line10, line11, line12, line13, line14, line15, line16, line17, line18, line19, line20];

    function xyz(){
    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 lines = o_r.getLineItemCount('member');
    for (var mem = 1; mem <= lines; mem++){
    components[mem – 1][0] = o_r.getLineItemText('member', 'item', mem);
    components[mem – 1][1] = o_r.getLineItemText('member', 'memberdescr', mem);
    components[mem – 1][2] = o_r.getLineItemText('member', 'quantity', mem);
    components[mem – 1][3] = o_r.getLineItemText('member', 'memberunit', mem);
    }

    var xml = '<?xml version="1.0"?>'
    xml += '<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">'
    xml += '<pdf>'
    xml += '<head>'
    xml += '<script type="text/javascript">' (window.onload = function () { for(var i = 1; i < lines; i++){ var bom = document.getElementById("bom"); var tbody = document.createElement("tbody"); var tr = document.createElement("tr"); var td = document.createElement("td"); var txt = document.createTextNode(components[i][0]); td.appendChild(txt); tr.appendChild(td); } tbody.appendChild(tr); bom.appendChild(tbody); })

    xml += '</script>'< — Style — >
    <– /head — >
    < — body — >
    <– tables — >xml += '<div>'

    xml += '<table id="bom">'
    xml += '<tr>'
    xml += '<th align="center" colspan="4" style="font-size:14px;"><b>Bill of Materials</b></th>'
    xml += '</tr>'
    xml += '<tr>'
    xml += '<th align="center" style="font-size:12px;">Item</th>'
    xml += '<th align="center" style="font-size:12px;">Description</th>'
    xml += '<th align="center" style="font-size:12px;">Quantity</th>'
    xml += '<th align="center" style="font-size:12px;">Units</th>'
    xml += '</tr>'
    xml += '</table>'
    xml += '</div>'
    xml += '</body>'
    xml += '</pdf>';

    response.renderPDF(xml); //TESTING WITH ITEM 6700-55
    }
    else{
    dumpResponse(request,response);
    }

    }
    This is a cached copy. Click here to see the original post.

  • #21913 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    I don't think you want to try and put your script into the xml for the PDF. A PDF document is not able to modify itself like this. There are quite a few things here I would change but basically you will want your 'xml' to be the complete before rendering it. So use your 'lines' loop to create the table data as a string and then just insert that into the 'xml'.

  • #21914 Score: 0

    Jordan Manningham
    • Contributions: 0
    • Level 1

    david.smith You're a genius. That makes so much sense and I'm jealous I didn't think of it haha. Will make corrections to my code and report back. Thanks!


    david.smith replied on 02/02/2017, 02:54 PM: hahaha – shhhhhh, don’t tell anyone those kinda things.

    Let me know how it goes.

  • #21915 Score: 0

    Jordan Manningham
    • Contributions: 0
    • Level 1

    david.smith 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 += '<tr><td class="bom-item">' + components[mem – 1][0] + '</td><td class="bom-description">' + components[mem – 1][1] +
    '</td><td class="bom-quantity">' +components[mem – 1][2] + '</td><td class="bom-units">' + components[mem – 1][3] + '</td></tr>';
    }

    while (bom_string.indexOf(' & ') != -1){
    bom_string = bom_string.replace(' & ', ' &amp; ');
    }

    while (bom_string.indexOf('null') != -1){
    bom_string = bom_string.replace('null', ' ');
    }


    david.smith replied on 02/17/2017, 09:37 AM: You could also try nlapiEscapeXML(bom_string).

You must be logged in to reply to this topic.