Add an Attachment coming from a sub list item?
Hello,
I have a dossier with sub items. How can I attach an attachment from a sub item as an attachment to an email?
I tried simply to use it like this: [[Standort.Attachments]] but the returned value is just a true or false.
Is there any useful documentation?
Many thanks and cheers
Joerg
-
Hi Joerg_K.
to understand your scenario: how do you define from which sub item? And what is the Standort field type and how is it used?
BR Matthias
0 -
This should help: How to use [[Attachment]] field placeholder on Modern Forms – skybow Portal
Consider the [[Attachment]] placeholder is just this fully extended on forms where the files are added. If you need the attachment information later in a background action or on another form think about saving the urls of the attached files into another field e.g. multiple line of text to access later more easy.
Hope this helps!0 -
Matthias_Walter
I do have a parent list (visitors list), each entry at the parent has a lookup to a location list. The location list has an option to have one attachment that contains a PDF file with directions and information in regards to the location itself. From the parent, via the lookup, this attachment should be send out via email to the guest.Christof
So the placeholder [[Attachment]] just returns "True" or "False" when used anytime later. Only at the runtime when creating an entry the [[Attachment]] has the properties described at the article you provided above. Means when an entry is created I need to make any validation I require and save the information about the URL and file name manually?
So at the validation I can use
var attachments = [[Attachments]];
var existingAttachments = attachments.Attachments.map(attachment => attachment.FileName);
var newAttachments = attachments.NewFiles.map(attachment => attachment.name);
var allAttachments = existingAttachments.concat(newAttachments);
var fileTypeValid = true;
if (allAttachments.length > 0) {
if (allAttachments.length === 1) {
fileTypeValid = allAttachments[0].split('.').pop().trim() === "pdf";
} else {
fileTypeValid = false;
}
}
var attachmentCountValid = attachments.Attachments.length + attachments.NewFiles.length < 2;
var isValid = fileTypeValid && attachmentCountValid;
return isValid;to ensure just one attachment has been added and that it is a PDF correct?
And I need to separately store/check/update the URL/Filename at my NewForm and EditForm right? So I use this:var attachment = [[Attachments]];
if ((attachment.Attachments.length + attachment.NewFiles.length) > 0)
return attachment.UrlPrefix + attachment.Attachments[0].FileName;
else
return "";
However, when a user deletes the attachment and uploads a new one I do get this error:Failed to evaluate property "Value" in "Set field value":
Error occurred on evaluating expression "{ var attachment = [[Attachments]];
if ((attachment.Attachments.length + attachment.NewFiles.length) > 0)
return attachment.UrlPrefix + attachment.Attachments[0].FileName; else return ""; }".
TypeError: Cannot read properties of undefined (reading 'FileName')I guess it is because the new item at the array is not having the index 0 at this time?
It would be nice if your documentation would give us an example how to store the path and filenames of attachments to be used and addressed at any later stage.Many thanks!
0 -
I think I have found the solution (not fully tested yet), I need to use a slightly different code:
var attachment = [[Attachments]];
if ((attachment.Attachments.length + attachment.NewFiles.length) > 0)
return attachment.UrlPrefix + attachment.NewFiles[0].name;
else
return "";and add a condition only to be executed if [[Attachments.IsChanged]] for the EditForm, because when removing an attachment and adding there will be again "NewFiles" having a value.
With the NewForm if there is an attachment it is always "NewFiles".
Many thanks again Christof0
Please sign in to leave a comment.
Comments
4 comments