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
-
said:
I would like to collect in an excel file the complet list of my different Navire.OptionsJust 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.
-
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.
-
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.
-
d.Offres.Options[i+1].Quantité, also tested without success….
-
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?
-
The printing template « test » is in the ‘NAVIRES’ table…
-
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.
-
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
} -
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.
-
I don't know if this help.
-
said:
Options Famille, but it just show me the ID of the selectionSince 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.
Content aside
- Status Answered
- 18 hrs agoLast active
- 17Replies
- 92Views
-
3
Following