0

Is it possible to separate out one big item table into smaller item tables by grouping based upon a common value of a specific field?

For example, if the item record had a field called 'Category' and the list options was 'Category A', 'Category B' and 'Category C', could the table be separated into 3 smaller tables?

Ryan
  • 1
  • 3

1 Answers1

1

There is syntax in the Advanced PDF template engine that's something like:

<#iftrue>
  <table></table>
<#else>
  <table></table>

I would recommend finding a PDF which does something similar to what you want and copy/edit the code to work for you.

However, with a bit of practice, I think you'll find it much easier to create PDF's with JavaScript and XML. I'm doing this from the top of my head, so some of it may be off. If you need help, or I've made an error, please don't hesitate to reach out.

The setup is a User Event, a Suitelet, and an XML file.

  1. User Event Script to display a button in view mode that opens a Suitelet when clicked:
/**
 * @NScriptType UserEvent
 * @NApiVersion 2.0 // 2.1 if you can
 */

define(["N/anyLibrariesYouNeed"), function(anyLibrariesYouNeed) {
  function beforeLoad(context){
    if (context.type === "view") {
      context.form.addButton({
        id: "custpage_print_pdf",
        label: "Print PDF",
        functionName: 'window.open("link_to_suitelet")'
  }

  return {beforeLoad: beforeLoad}
})
  1. Suitelet which is opened from the above User Event, and replaces placeholder text in the XML file with conditional text:
/**
 * @NScriptType Suitelet
 * @NApiVersion 2.0 // 2.1 if you can
 */

define(["N/file", "N/search", "N/anyLibrariesYouNeed"], function(file, search, anyLibrariesYouNeed) {
  function onRequest(context) {
    // Load the PDF, which is just an XML file
    var myPDF = file.load("path_to_your PDF").getContents();

    // Load the search
    var mySearch = search.load({id: "mySearchId"});

    // Do some stuff with the results ...
    var myResults = [];
    mySearch.run.each(function(result){
      // ... like generate a </table> or group results with Lodash
    })

    //Just make sure all the placeholder text in your XML (PDF) file is replaced. If it's not do ... 
    myPDF = myPDF.replace("Placeholder", "With this");

    //Finally, render the PDF from XML using the bigfaceless engine provided by NetSuite. The setup for bigfaceless is in the XML file.
    context.response.renderPdf(myPDF);
  }
  return {onRequest: onRequest}
})
  1. Placeholder XML file which is rendered as a PDF using context.response.renderPdf(myPDF)
//big_face_less_tag_goes_here and something like DOCTYPE XML
<pdf>
  <head>
    <style>
      table tr th td {
        border: 1px solid black
      }
    </style>

    <body>
      Placeholder
    </body>
</pdf>

Hope that helps. If you need help, just holler!

zerecees
  • 697
  • 4
  • 13
  • Just want to say thanks for the input - really appreciate the help. However, I think I am a little out of my depth on this one. – Ryan Apr 06 '20 at 20:07
  • I could do with some hand-holding to walk through on a step-by-step basis but not sure if you have time available at all to help? – Ryan Apr 06 '20 at 20:07
  • Hi @Ryan! I do tomorrow. I'll be sure to connect with you in this comment section tomorrow. For now, could you tell me what you are having trouble understanding? For example, is it JavaScript? Uploading scripts? The Suitelet module? Don't worry about not understanding, NetSuite's a beast and takes some time. But, if you could help me with a starting point, that would make our time more efficient. Don't worry about fitting something in one session either. We'll figure out. Looking forward to your reply -zerecees – zerecees Apr 07 '20 at 00:25
  • Thanks! - it is a bit of everything as new to coding and still learning the basics and able to get by with a bit of trial and error but definitely feel out of my depth with this exercise. – Ryan Apr 07 '20 at 08:08
  • Essentially what I have is a list based on item records which creates a table with the headings called; 'Product Code', 'Product Description', 'VAT Amount' etc. – Ryan Apr 07 '20 at 08:21
  • There is a field called 'External System Category' which is stored on the item record and is used by the company's website to categorize the products they sell. – Ryan Apr 07 '20 at 08:23
  • The field called 'External System Category' is a multi-select field. From what I understand this means I cannot source this field from the Advanced PDF/HTML templates. I have therefore created a copy of this field and renamed it 'List Roll Up'. I have performed a mass update to copy the details in the field called 'External System Category' to the custom field I created called 'List Roll Up'. I can now source my custom field onto the Advanced PDF/Template. – Ryan Apr 07 '20 at 08:27
  • But rather than just have a 78 page list of all the products, it would be great to divide this list into smaller tables based on the product category. Not sure if this makes sense at all? – Ryan Apr 07 '20 at 08:30
  • It makes sense and I am able to map your thought process. From a system perspective, we can avoid the upload you did to link the multi-select field to what I assume is a text field. However, I see what you were trying to do and commend you for thinking around the problem! I still plan to reach out to you today, and now that I understand what you are trying to do better, I think it will help a lot. I will write back with what I think you should do in my answer section above, and we can go from there. Does that sound fair and work for you? – zerecees Apr 07 '20 at 14:35
  • Hi @Ryan. I apologize as I did not have time today to revisit your post to the depth which I wanted, please give me a few more days. I will be sure to get back to you though! – zerecees Apr 08 '20 at 06:16
  • No worries - appreciate the reply! – Ryan Apr 08 '20 at 15:58
  • Hi Zerecess, hope you are doing OK. Just wondered if you were able to get a moment to share your expertise - happy to take this offline / screen share if possible? Thanks – Ryan Apr 14 '20 at 19:14
  • Hey Ryan! So sorry, I’m embarrassed to admit I forgot over the week. I do not have anyone else to respond to on stack, so let me jump on this right away! – zerecees Apr 14 '20 at 22:18
  • Hi @Ryan! Thanks so much for your patience. I tried using the advanced PDF template again and to be candid, I didn't get very far. Most of the work I do like this leverages [lodash](https://lodash.com/docs) and JS/HTML, rendered with BigFaceless. Are you ok if I target my answer to that? It will be completely off topic from your original question, that's why I want to make sure it's something you're ok with first. – zerecees Apr 17 '20 at 04:53