Switch
Can anybody tell me what is wrong here ?
ninox gives an error at case 2 where it says that keyword 2 is not found. I have tried without ";" - same problem, and also tried to remove case 2, but still the same problem although it is now case 3 which gives the problem - it is like Xcount for some reason is not accepted, and I cannot use Tempid for the switch as I can not be sure about the idnumber.
What I am trying is to insert all images in the db as attachments to the mail even if there are 1 or 5 pictures.
let Xcount:=number(count(select dokumentation where 'Sagsnr.'=1));
for i in (select dokumentation where 'Sagsnr.''=1) do
switch Xcount do
case 1 : let Xattach5 := i.billede
case 2 : let Xattach4 := i.billede
case 3 : let Xattach3 := i.billede
case 4 : let Xattach2 := i.Billede
case 5 : let Xattach1 := i.Billede
default:=null
end;
Xcount:=Xcount-1;
end;
sendEmail({
from: userEmail(),
to: "leowoer@icloud.com",
replyTo: "leowoer@icloud.com",
subject: "Dokumentation for saggsnr. " + Sagsnr,
text: "Dette er en test",
html: "",
attachments: [Xattach1,Xattach2,Xattach3,Xattach4,Xattach5]
})
4 replies
-
said:
What I am trying is to insert all images in the db as attachments to the mail even if there are 1 or 5 pictures.If you need to create an array of documents then the switch will not help. Maybe try something like:
let xAttachments := for i in (select dokumentation where 'Sagsnr.''=1) do i.billede end;
Remember to reduce the number of select statements in your code as they are very slow. You have the same select statement in the first two lines so try something like:
let dokuRecs := (select dokumentation where 'Sagsnr.'=1); let Xcount:= count(dokuRecs); let xAttachments := for i in dokuRecs do i.billede end;
But since you are working with attachments to be sent through email so I don't know if this will work or if you need shareFile() or something else.
Now you can try putting it all together:
sendEmail({ from: userEmail(), to: "leowoer@icloud.com", replyTo: "leowoer@icloud.com", subject: "Dokumentation for saggsnr. " + Sagsnr, text: "Dette er en test", html: "", attachments: xAttachments })
-
Fred
again you came with an ingenious solution - this just works with however how many pictures I have as documentation
Thank You very much for this great help - I owe you one
rgds
Leo
And PS. I will mark it as answered
-
To make the switch functional, but still not the method to use, is to put parentheses around the code in the cases.
for i in (select dokumentation where 'Sagsnr.''=1) do switch Xcount do case 1 : (let Xattach5 := i.billede) case 2 : (let Xattach4 := i.billede) case 3 : (let Xattach3 := i.billede) case 4 : (let Xattach2 := i.Billede) case 5 : (let Xattach1 := i.Billede) default:=null end;
Ninox is looking for simple data for a case, so if you want to do more coding then you have to put it within the parentheses so Ninox knows what to do.
Content aside
- Status Answered
- 2 days agoLast active
- 4Replies
- 36Views
-
2
Following