Trying to e-mail with record in PDF attached

Ninox Profile

Hi all!

Is it me or is mailing with attachments (record in PDF format) still not functioning properly? I have read many threads on this issue and as long as I am working with Ninox I still haven't figured out what the problem (sometimes) seems to be...

In my table Invoices, I have a button to e-mail the invoice. The button coded as usual (printAndSaveRecord & importFile), attachment is file(this, xPdf, xFile) and then upon pressing the button, the error appears that Ninox cannot find the PDF. Now, I have read the threads and it seems that Ninox cannot find the file as it has not yet been generated before and/or uploaded into the cloud. However, this error also occurs when I am working in browser window. Second time I try to e-mail the file, it works.

I have tried to fix this with the "do as server" command, but this makes no difference.

I have tried to put some other code between printAndSaveRecord and the attachment command in the e-mail 'module' of the code in order to give Ninox some extra time. But also this makes no difference.

Then it gets even crazier: in another Table called Shipments, I use the exact same code, the e-mail is sent, but no attachment is actually attached...

Logic dictates it must be me doing something wrong, but I cannot seem to figure out what it is. Only thing I can think of is that in the Shipment table the e-mail is sent upon a 'trigger after update' and in the Invoice table the e-mail is sent upon clicking a button. Could this be why the PDF is not attached? And if so; it makes no sense to me why not.

In general: is anyone else also experiencing these issues? How can they be fixed? I have tried generating a PDF upon creating the record (trigger on new record in the table), but this also does not work.

 

M

I'm using several buttons with various send email+ attachment (cloud version) which is used some 10 times day and apart from when setting up and testing (approx 9 months ago) I have never had any issues.

can I suggestion you upload your script and we can try and replicate it?

Ninox Profile

Hi Mel,

My coded button in the Invoices table is:

 

if 'INVOICE TO'.'RELATION TYPE' = 1 then
let x := Id;
let xCust := 'INVOICE TO';
let xPDF := printAndSaveRecord(this, "INVOICE");
let xFile := 'INVOICE NUMBER' + ".pdf";
importFile(this, xPDF, xFile);
for a in select CONTACTS where RELATIONS = xCust and STATUS = 1 and 'E-MAIL INVOICES' = true do
sendEmail({
from: userEmail(),
to: a.'E-MAIL',
subject: 'INVOICE NUMBER',
text: " ",
attachments: file(this, xFile),
html: "Dear " + a.TITLE + " " + a.'LAST NAME' + ",<br><br>Please find attached invoice " + ".<br><br>Thank you and best regards,<br><br>" + user() + "<br><br><b><u>ATTACHMENTS:</u></b><ul><li>" + 'INVOICE NUMBER' + "</li></ul>"
})
end;
STATUS := 3;
SENT := true
else
if 'INVOICE TO'.'RELATION TYPE' = 2 then
let x := Id;
let xCust := 'INVOICE TO';
let a := (select RELATIONS where Id = xCust and 'E-MAIL INVOICES' = true);
let xPDF := printAndSaveRecord(this, "INVOICE");
let xFile := 'INVOICE NUMBER' + ".pdf";
importFile(this, xPDF, xFile);
sendEmail({
from: userEmail(),
to: a.'GENERAL E-MAIL',
subject: 'INVOICE NUMBER',
text: " ",
attachments: file(this, xFile),
html: "Dear " + a.TITLE + " " + a.'LAST NAME' + ",<br><br>Please find attached invoice " + ".<br><br>Thank you and best regards,<br><br>" + user() + "<br><br><b><u>ATTACHMENTS:</u></b><ul><li>" + 'INVOICE NUMBER' + "</li></ul>"
});
STATUS := 3;
SENT := true
end
end;

 

The code in the Shipments table is actually the same (it's a Shipment form instead of an Invoice form obviously). Only difference is that in the Shipments table it is a 'trigger after update' event and not a button. In the Shipments table, the E-mail is sent, but the attachment is not there.

Code is:

 

if 'WAREHOUSE STATUS' = 1 then
'SHADOW WAREHOUSE STATUS' := 1
else
if 'WAREHOUSE STATUS' = 2 then
'WAREHOUSE IN' := now();
'SHADOW WAREHOUSE STATUS' := 2
else
if 'WAREHOUSE STATUS' = 3 then
'SHADOW WAREHOUSE STATUS' := 3;
let x := Id;
let i := (create LOG);
i.(SHIPMENTS := x);
i.('LOG NUMBER' := text(record(COUNTERS,6).RESULT));
let c := record(COUNTERS,6).(COUNTER + 1);
record(COUNTERS,6).(COUNTER := c);
i.('CREATED BY' := upper(text(user())));
popupRecord(i)
else
if 'WAREHOUSE STATUS' = 4 then
if 'INCO TERM' = null then
let x := 'SHADOW WAREHOUSE STATUS';
alert("INCO TERM EMPTY");
'WAREHOUSE STATUS' := x
else
'SHADOW WAREHOUSE STATUS' := 'WAREHOUSE STATUS'
end
else
if 'WAREHOUSE STATUS' = 5 then
'SHADOW WAREHOUSE STATUS' := 5
else
if 'WAREHOUSE STATUS' = 6 then
'SHADOW WAREHOUSE STATUS' := 6
end
end
end
end
end
end;
if CUSTOMER.'RELATION TYPE' = 1 then
let x := Id;
let xCust := CUSTOMER;
for a in select CONTACTS where RELATIONS = xCust and STATUS = 1 and 'E-MAIL SHIPMENT INFO' = true do
do as server
let xPDF := printAndSaveRecord(this, "INVOICE FORM");
let xFile := 'SHIPMENT NUMBER' + ".pdf";
importFile(this, xPDF, xFile);
sendEmail({
from: userEmail(),
to: a.'E-MAIL',
subject: 'SHIPMENT NUMBER' + ": STATUS UPDATE",
text: " ",
html: "Dear " + a.TITLE + " " + a.'LAST NAME' + ",<br><br>Please be informed that the status of shipment " + 'SHIPMENT NUMBER' + " has been changed to:<br><br><b>" + 'WAREHOUSE STATUS' + "</b><br><br>Best regards,<br>" + user() + "<br><br><b><u>ATTACHMENTS:</u></b><br><ul><li>" + 'SHIPMENT NUMBER' + "</li></ul>",
attachment: file(this, xFile)
})
end
end
end

J

Hi Martijn

 

I tested some code based on your construction and it sent emails perfectly.

 

In your code to send Invoices you have

 

let a := (select RELATIONS where Id = xCust and 'E-MAIL INVOICES' = true);

 

This sets a to be an array even if it has a single element. Either use for a in (select RELATIONS... or let a := first(select RELATIONS...

 

Is RELATIONS the customer table referenced with 'INVOICE TO' from the Invoice table?

 

Both this code and the Shipment code can be significantly tidied up if you would like me to post examples.

 

Regards John

Reply