0

Multiple records print with button

Hi,

Is there a way to print multiple pages (records) in a button ?

For one page, it already works with this :

let myPdf := printRecord(this, "name");

Actually, I can already do it with the print button in ninox and then select the "all" function but I would like to do it in a button.

Thanks a lot.

Lorenz

Screen Shot 2018-11-06 at 00.36.53

26 replies

null
    • asbl
    • 5 yrs ago
    • Reported - view

    Hello,

     

    Does someone know how I cloud do this ?

    Thanks for your support.

    Lorenz

    • Alexander_Koenig
    • 5 yrs ago
    • Reported - view

    Hi Lorenz,

    this is possible if you iterate with a for loop.

    Best regards, Alex

    • Support
    • 5 yrs ago
    • Reported - view

    Hi Lorenz, 

    it should be able to do that with the same formula but in a loop: 

     

    for i in select table where fieldA = "AB" do

    printRecord(this,"name")

    end

     

    Best, Jörg

    • David_Sarrocco
    • 2 yrs ago
    • Reported - view

    Hi Support,

    With your suggestion there will be printed a lot of PDF (one per record). With the "Tout" (see the image above) they will be ALL printed in UNIQUE pdf. How it is possibile to reproduce this by usign a button/formula?

    • Créateur de bien-être
    • Sebastien_Guillet
    • 11 mths ago
    • Reported - view

    I'm also interested if anyone has any idea how to combine multiple pdf's into one

    • Ninox developper
    • Jacques_TUR
    • 11 mths ago
    • Reported - view

    With Ninext (https://forum.ninox.com/t/p8h78zv?r=g9ha3vf), you can do it : 

    var strThis := string(this.id);
    var Nids := (select myTable).string(id);
    var reportName := "myReportName";
    var fileName := "myFile.pdf";
    var link := #{:link:callback
        var config = {
            nid: strThis,
            nids:  Nids,
            reportName: reportName,
            saveToFileAndClose: (err, file) => callback(err?err:file)
                       };
        return schemas.envConfig.openDesigner(config);
    }#;
    importFile( this, link, fileName)
    

    Just change the parameters of lines 2, 3 and 4. 

      • Créateur de bien-être
      • Sebastien_Guillet
      • 11 mths ago
      • Reported - view

      Jacques TUR Thanks for your feedback. Where do I put this code?

      • Ninox developper
      • Jacques_TUR
      • 11 mths ago
      • Reported - view

      Sébastien Guillet in the formula of a button. 

      You can also create a global function to use it in several places in your database. 

      function printAndDownloadMutiRecord( strNids : text, reportName : text, fileName : text ) do
      var n := split(replace(strNids," ",""),",");
      #{    var config = {
              nid: n[0],
              nids:  n,
              reportName: reportName,
              printAllAndClose: !0
                         };
          schemas.envConfig.openDesigner(config);
      }#;
      end;
      

      And call it that:

      printAndDownloadMutiRecord( concat((select myTable where myField like myFilter).string(id)), "myReport", "myFileName" );
      

      ps: in this version, I have deleted strThis and replaced it with the first Nids record.

      • Créateur de bien-être
      • Sebastien_Guillet
      • 11 mths ago
      • Reported - view

      Jacques TUR THANKS ! I understand the idea better. However, I misspoke. I would like to be able to combine 2 pdf of the same record (2 different print models).

      Currently I use a button with this formula:

      Facture := importFile(this, printAndSaveRecord(this, "Facture_template_dynamique"), "Facture " + 'N° de transaction' + " - " + Compte.'Nom concaténé du compte' +
          ".pdf");
      Annexe := importFile(this, printAndSaveRecord(this, "Annexe_facture_template_dynamique"), "Annexe à la facture " + 'N° de transaction' + " - " +
          Compte.'Nom concaténé du compte' +
          ".pdf")
      

      It is an invoice and an appendix to this invoice. To facilitate the sending of the invoice and its appendix, I would like the 2 files to be combined on the same pdf file. which I can download directly to my computer, in my default download folder.

      Is it possible ?

      • Ninox developper
      • Jacques_TUR
      • 11 mths ago
      • Reported - view

      Sébastien Guillet 

      To have everything in the same file, to date, the best is to use the dynamic report which allows to build very complete and complex reports.

      Otherwise it is possible to zip the two files together with the createZipFile function: https://forum.ninox.com/t/m1habhz/new-functions 

      • Créateur de bien-être
      • Sebastien_Guillet
      • 11 mths ago
      • Reported - view

      Jacques TUR 

      Thank !

      Unfortunately, I will not be able to use the dynamic reports because the 2 documents are an invoice and an appendix containing personal data. The invoice has page numbers and the appendix should not be part of this numbering because the appendix is a document that is not intended to be sent to mutual insurance companies (I work in health/well-being). If my client removes the second page (the appendix), the health insurance company will find that a page is missing and may request the second page believing that it is the rest of the invoice.

      As for createZipFile(), the idea is good but in my case, it's the same because I will have 2 pdf files and not one. I would waste time decompressing which I don't currently need to do.

      I will continue to work with my 2 separate files. Thank you for the previous explanations, I have already been able to use the formulas to integrate export buttons on my dashboard. It's very useful !

      • Ninox developer
      • Fabio
      • 11 mths ago
      • Reported - view

      Jacques TUR , I think the code ignores the name assigned to the file (fileName) using the default name of the record. Could you take a look?

      Thanks!

      • Ninox developper
      • Jacques_TUR
      • 11 mths ago
      • Reported - view

      Fabio Of course, but which of the three codes are you talking about?

      • Ninox developer
      • Fabio
      • 11 mths ago
      • Reported - view

      Jacques TUR , the global function:

      function printAndDownloadMutiRecord( strNids : text, reportName : text, fileName : text ) do
         var n := split(replace(strNids," ",""),",");
         #{
            var config = {
               nid: n[0],
               nids: n,
               reportName: reportName,
               printAllAndClose: !0
            };
            schemas.envConfig.openDesigner(config);
         }#;
      end;
      

      Thanks

      • Ninox developper
      • Jacques_TUR
      • 11 mths ago
      • Reported - view

      Fabio You are right, fileName is never used 😅.

      Please use this tow functions. One to print and retrieve the URL of pdf, seconde to download one URL : 

      function downloadURL(urlFile : text,destFileName : text) do
          #{:text:callback
              fetch(urlFile)
                  .then(resp => resp.blob())
                  .then(blob => {
                      const url = window.URL.createObjectURL(blob);
                      const a = document.createElement('a');
                      a.style.display = 'none';
                      a.href = url;
                      a.download = destFileName;
                      document.body.appendChild(a);
                      a.click();
                      window.URL.revokeObjectURL(url);
                      callback(url.url);
                  })
      }#
      end;
      function printAndDownloadMutiRecord(strNids : text,reportName : text) do
          var n := split(replace(strNids, " ", ""), ",");
          #{:text:callback
          var config = {
               nid: n[0],
               nids: n,
               reportName: reportName,
              saveToFileAndClose: (err, urlFile) => callback(err?err:urlFile)
                         };
           schemas.envConfig.openDesigner(config);     }#
      end;
      

      Then you can call them in succession :

      var urlFile := printAndDownloadMutiRecord(concat((select Customer where 'First Name' like "S").string(Id)), "Kunde");
      downloadURL(urlFile, "myFileName.pdf")
      

      note: printAndDownloadMutiRecord() requires Ninext, but not downloadURL()

      • Ninox developer
      • Fabio
      • 11 mths ago
      • Reported - view

      Thanks Jacques TUR. Now it works, however the multiple download no longer works correctly: the pdf is generated only for the first record of the selection 🤔.

      • Ninox developper
      • Jacques_TUR
      • 11 mths ago
      • Reported - view

      Fabio I had not paid attention to that. I had to modify the code a bit more to get the selection of several records AND the choice of the file name:

      function printAndDownloadMutiRecord(strNids : text,reportName : text,fileName : text) do
          var n := split(replace(strNids, " ", ""), ",");
          #{:text
          var config = {
               nid: n[0],
               nids: n,
               reportName: reportName,
              printAllAndClose : !0
                         };
          var old = database.printRich;
          database.printRich = (e, t) => { try {e.name = fileName; old.call(database, e,t)} finally {database.printRich = old}}
          schemas.envConfig.openDesigner(config);
         }#
      end;
      
      

      To be called with this code:

      printAndDownloadMutiRecord(concat((select Customer where 'First Name' like "S").string(Id)), "Kunde", "myFileName.pdf");
      
      • Ninox developer
      • Fabio
      • 11 mths ago
      • Reported - view

      Great!. Now it works perfectly.

      Thank you Jacques

    • Ninox developper
    • Jacques_TUR
    • 11 mths ago
    • Reported - view

    I updated last function and i ranmed it printAndSaveMutiRecord. Now it print and retrieve one URL link of the file. With this, link, you can decide to download it or save it to attached documents of record :

    function downloadURL(urlFile : text,destFileName : text) do
        #{:text:callback
            fetch(urlFile)
                .then(resp => resp.blob())
                .then(blob => {
                    const url = window.URL.createObjectURL(blob);
                    const a = document.createElement('a');
                    a.style.display = 'none';
                    a.href = url;
                    a.download = destFileName;
                    document.body.appendChild(a);
                    a.click();
                    window.URL.revokeObjectURL(url);
                    callback(url.url);
                })
    }#
    end;
    
    function printAndSaveMutiRecord(strNids : text,reportName : text) do
        var n := split(replace(strNids, " ", ""), ",");
        #{:text:callback
        var config = {
            nid: n[0],
            nids: n,
            reportName: reportName,
            printAllAndClose: !0
        };
        var old = database.printRich;
        database.printRich = (e, t) => {
            old.call(database, e, (err, result) => {
                callback(database.loadFileURL(result.id, e.name, "application/pdf", !0));
            })
            database.printRich = old
        }
        schemas.envConfig.openDesigner(config);
       }#
    end;
    
    var urlFile := printAndSaveMutiRecord(concat((select Customer where 'First Name' like "S").string(Id)), "Kunde");
    
    downloadURL(urlFile, "myFileName.pdf");
    
    importFile(this, urlFile, "myOtherFileName.pdf")
    

    Line 39 : the report is printed with several records and returns a URL link.

    Line 41 : the link is used to download the file with a specific file name.

    Line 43 : the link is used to attach the file to this record with the standard Ninox function, again with a specific file name.

    note: in the previous version of printMultiRecord, asynchronous mode is not really supported and you can have problems if you call the function several times successively. 

    • Ninox developper
    • Jacques_TUR
    • 11 mths ago
    • Reported - view

    Please find an example of printing in the attached database. See the ViewEvent table.
    Lots of news on this page:
    - The customer list is retrieved from the 'Customer list' field. This means that the print button takes into account the filter and the order of the list. 
    - The download button asks for the name of the file before downloading it.
    - and, of course, the print button allows you to print multiple records on the same report.
     

      • Ninox developper
      • Jacques_TUR
      • 11 mths ago
      • Reported - view

      Erratum: I uploaded the wrong version of the demo database. Please find the correct version.

      After a short test, it seems that the database does not work properly on Mac. I will try to fix this as soon as possible.Ninext 2.ninox 

      • Rafael Sanchis
      • Rafael_Sanchis
      • 11 mths ago
      • Reported - view

      Jacques TUR Look to good on Android Table.

      • Ninox developer
      • Fabio
      • 3 mths ago
      • Reported - view

      Hello

      after the latest updates the code above, the one that allows the generation of a pdf containing several records, no longer works.

      • Ninox developper
      • Jacques_TUR
      • 3 mths ago
      • Reported - view

       Indeed, since version 3.10.8 of Ninox, calls to JavaScript with Native JS ( #{...}# ) no longer work. I have just published a version 2.1.31 to correct this.

      However, the call to OpenDesigner, which allowed printing multiple records at the same time, is currently not available. I will try to get it working again, but nothing is certain at the moment. A workaround would be to use Dynamic Reports, which allow doing this using JSON as input data

Content aside

  • 3 mths agoLast active
  • 26Replies
  • 2867Views
  • 4 Following