0

Excel scripting with carbone

Hello community!

I’m struggling a bit with carbone template scripting:

I would like to collect in an excel file the complet list of my different Navire.Options liked to a single Offer in the parent table Offer (see below my DB diagram). this template has to be in the navires table (I send it with an email button with others templates in the navires table…)

Example: I have one offer with 2 vessels. Each vessel has différent options. I would like to collect all the list of options of this 2 vessels in a single excel sheet.

I try to script the some excel attached, but it’s always blank

Any idea? Maybe there is an easiest way to collect a list with a standard ninox printing engine and a wonderful formula!?

Thanks for your help!

17 replies

null
    • Fred
    • 5 days ago
    • Reported - view
     said:
    I would like to collect in an excel file the complet list of my different Navire.Options

    Just to clarify that Ninox can only output into PDF through dynamic printing. Carbone can export into XLSX, but that is something else.

    If you want to output into excel then you need to use createXLSX().

    Let us know which way you want to go.

    • frsalabert.1
    • 5 days ago
    • Reported - view

    Hello Fred! Thanks for your care, you’re the one who help me the most!

    no problem if ninox generate a pdf as I’ve created an email button to send in one click the « dce », « dmec » and this « test » template.

    • Fred
    • 4 days ago
    • Reported - view

    In Carbone you place the repetition code at the level where you need to repeat. So the first column code would look like:

    {d.Offres.Options[i].Quantité}
    {d.Offres.Options[i+1].Quantité}
    

    Give that a try. If it works then try to figure out where the repetition code for the second column.

      • frsalabert.1
      • 4 days ago
      • Reported - view

       hum… always blank. I think the issue is in the scripting. I’ve attached a diagram to clearly figure what I need to collect: I need , in a simple list with 2 columns, to collect all the options (qty & name) of the vessels that are linked in the same Offer. It’s easy to do with standard printing template in the Offer parent table, but unfortunately, I need this printing template to be in the Navires child table. Whatever the try in different templates (carbone or standard), I always have data access to the child table, never to the parent table…

    • frsalabert.1
    • 4 days ago
    • Reported - view

    d.Offres.Options[i+1].Quantité, also tested without success….

      • Fred
      • 3 days ago
      • Reported - view

       I just noticed that the names in your Carbone code does not match the tables names in your picture. Unless you renamed the reference fields from upper case to lower case. Also Carbone does not like accented names, so Quantité won't resolve. If you tried another field with no accents it should work, well if you also made sure that Offres is Offres and not OFFRES.

      So you may want to look into creating JSON data sets so you can rename your fields without having to actually rename your fields.

      • frsalabert.1
      • 3 days ago
      • Reported - view

       noticed. I changed it. But same result.

    • Fred
    • 3 days ago
    • Reported - view

    So I created your basic structure:

    Is Options supposed to be a M:M (many to many) connection between OFFRES and NAVIRES? If so then you don't need the direct connection between OFFRES and NAVIRES, since OPTIONS does that for you.

    Here is what the data looks like from NAVIRES:

    Attached is my odt file, but the code is:

    {d.OFFRES.OPTIONS[i].QUANTITY}
    {d.OFFRES.OPTIONS[i+1].QUANTITY}
    

    Attached is the print out, but here is a pic of it:

    Can you upload a copy of your DB?

    • frsalabert.1
    • 3 days ago
    • Reported - view

    The printing template « test » is in the ‘NAVIRES’ table…

      • Fred
      • 2 days ago
      • Reported - view

       The DB is empty of data. Can you provide some test data?

    • Fred
    • 2 days ago
    • Reported - view

    Thanks for the DB. It helps to see the field names.

    Here is what works for me.

    Since we can't have accented characters I created a simple JSON formula:

    {
        nav: Navire,
        Options: for i in Options do
            {
                name: i.'Commentaire Option',
                qnty: i.'Quantité'
            }
        end
    }

    I put in data in the above fields. You can copy the code into a formula field in the Navires table and see if you see any data. Here is what it looks like in my version:

    If you see no data under Options then you don't have linked records. Which means you will not see any results in your printing.

    If you see data under Options, then remember to copy the code into the dynamic print layout under JSON data input.

    I'm skipping the Offres link as it is unnecessary since you already have a Options link.

    Here is the Carbone code:

    {d.Options[i].qnty}
    {d.Options[i+1].qnty}

    Here is what is looks like in the record:

    And attached is the output.

    • frsalabert.1
    • yesterday
    • Reported - view

    I succeed in following your steps with the json formula below:

    {
        nav: Navire,
        Options: for i in Options do
            {
                name: i.Options.Designation,
                qnty: i.Quantite
            }
        end
    }

    But (sorry for the ‘but’), what I expect from carbone is not only collect the options of one vessel but also the options of others vessels linked under the same order (OFFRES tables). I can do it easy with a standard ninox printing in the offre table, but I need the printing to be in the Navires table (I send it by email with others template located in Navires table)

    So, has a newbie, I try this json below closer to my need, but I get ‘500 server internal error’…

    {
        nav: Navire,
        Options: for i in Options do
            {
                name: i.Offres.Options.Options.Designation,
                qnty: i.Offres.Options.Quantite
            }
        end
    }

    • Fred
    • yesterday
    • Reported - view

    You can try:

    {
        nav: Navire,
        Options: for i in Offres.Options do
            {
                name: i.Options.Designation,
                qnty: i.Quantite
            }
    }

    Offres is single reference field, but Options is multireference field. That means you can just reference Offres, but you have to use a for loop to interate through the Options reference link.

    The confusing naming scheme is you have a reference field called Options under the Options table. It points to another table, Fiche Options. But since it is also a single reference field you can use it easily in the code.

    Since you want to see all Options under a particular Offres, I don't know why you don't start in Offres.

      • frsalabert.1
      • 19 hrs ago
      • Reported - view

       It is working fine now!!I had a selection fiels in the json script which is Options Famille, but it just show me the ID of the selection not the name of the famille and need to short this column by famille ascendant:

      {
          nav: Navire,
          Options: for i in Offres.Options do
              {
                  name: i.Options.Designation,
                  qnty: i.Quantite,
                  fmlle: i.Options.Famille         ——>just the number of the field not its name
              }
          end
      }

       

      The reason why I don’t do that template easily in Offre table is that I have an email button in Navires table that send this template and 3 others from Navires. I did not see nothing that allow to send in one button the templates stored in different tables…

    • Rafael Sanchis
    • Rafael_Sanchis
    • yesterday
    • Reported - view

    I don't know if this help.

    https://forum.ninox.de/t/h7yt65a

    • Fred
    • 19 hrs ago
    • Reported - view
     said:
    Options Famille, but it just show me the ID of the selection

     Since Famille is a simple choice field, you can wrap it with text() and it will show the text of the choice.

    With printAndSaveRecord() you can print any template from any table. But it does take some reworking of the code. So a future project.

    I'm glad it is working now.

      • frsalabert.1
      • 18 hrs ago
      • Reported - view

      once again many thanks to you Fred!

Content aside

  • Status Answered
  • 18 hrs agoLast active
  • 17Replies
  • 92Views
  • 3 Following