LUA example: Print several orders together

In this example we’ll see how to create a printout that merges several orders together using the document object.

Script Group
Program
Event
Action
 tabella = database.getsql("SELECT gguid FROM ordini WHERE eli=0")

We start by extracting the orders to print. In this case we’ll take them all. Of course, it’s better to add some kind of filter, for example by date or customer.

To print them, we only need the gguid of each order


righe = tabella.getrows()

stampa = nil

for i = 1,tabella.countrows() do

if stampa == nil then

stampa = database.createdocument("gguidstampa", "ordini",righe[i].getvalue("gguid"))

else

stampa2 = database.createdocument("gguidstampa", "ordini",righe[i].getvalue("gguid"))

stampa.adddocument(stampa2)

end

end

if stampa ~= nil then

stampa.show()

end

We go through all the rows of the table. We created an empty stampa object because we need a first document that collects all the others.

Once the stampa object is set, all the other orders are appended to it.

Finally, if there is at least one printout, we show it.