Logic Machine Forum
new line - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: new line (/showthread.php?tid=4508)



new line - PassivPluss - 18.01.2023

Hi in this for function, the texts are stringed together and sent on an email. This is for the alarm window 
But what do I have to add in the end to get a new line between each alarm entry?

I tried to send mail in the for function directly but only the last alarm is then sent by email for some reason. Why is that?

what do i use to get the number for the current row in the rows function?

What do I use to get the total number of rows in the table?

maileksport = " "
for _, row in ipairs(rows) do
  alstmaxid = math.max(alstmaxid, row.id)
  alertdate = os.date('%c', row.alerttime)
  maileksport = maileksport .. (  "Alarmnr \n \n " .. " - " .. ((alertdate .. " - ".. row.alert  )) ) --- here i want a new line
    --  mail(mailalarm, (lokasjon ..  " - ALARM " ), alertdate .. " - ".. row.alert )   --- this only send the last entry in table as alarm

   
end


RE: new line - admin - 18.01.2023

Either change "Content-type" header to "text/plain" or use html <br> for line breaks.


RE: new line - PassivPluss - 18.01.2023

Will try. Thx.
Regarding to get active row in for function. How do i get that?

Total lines is table is #row

How about the mail function, why does only the last line in table rows send an mail?
Does it overwrite the varables before the mail function is run?


RE: new line - admin - 19.01.2023

The current index is the first variable in the loop:
Code:
for index, row in ipairs(rows) do
  log(index)
  ...
end

It should send an email for each entry in the table. Log what the mail function returns:
Code:
res, err = mail(...)
log(res, err)