Hi,
I'm looking for a way how to enable user who opens form in Edit to get list of URLs of Attachments from Child List. Parent and Child are referenced by field RequestNumber.
I thought we can use List control but we can not get attachments URL displayed instead of icon.
I also tried to get all of URLs via pnp and add them to a html control, but without success. I'm not that skilled in JS, to get those URLS and what is strange I couldn't add content to htmlControl.
Hello,
Thank you for quick reply.
I have already tried this attempt. But have met 2 obstacles:
Attachment file name must be unique for library - of course I can try with dynamic folders or change file name with code (I haven't tried but assume it is possible).
Upload opens windows explorer window instead of prepared Form. I created new library, added required Lookup, and my own fields like document type - user assigns from ddl, requestnumber from parent - additional reference to filter control). In parent form I changed to Editing :: Dialog.
What could go wrong here?
You can get URLs of all files attached to child items using PnP request. Add the Rich text control to the form, update list name and the site URL in the code.
var id = fd.itemId;
var fileURL = [];
var html = '';
pnp.sp.web.lists.getByTitle("ListName").items.filter("ParentId eq " + id).get().then(function(items) {
items.forEach(function(item) {
pnp.sp.web.lists.getByTitle("ListName").items.getById(item.Id).attachmentFiles.select("ServerRelativeUrl")().then(function(file) {
if (file.length > 0) {
file.forEach(function(f) {
fileURL.push(f.ServerRelativeUrl)
})
}
})
})
return fileURL
}).then(function(fileURL) {
setTimeout(function() {
for (let j = 0; j < fileURL.length; j++) {
html += '<a href="' + 'https://contoso.sharepoint.com' + fileURL[j] + '">' + 'File ' + j + '</a> <br>'
}
$(fd.control('RichText1').$el).html(html)
}, 1000)
});
@mnikitina Thank you! Your code is very supportive.
I had seen earlier similar code on this Community but it was not fully clear how to get to items in second API call.
where rnumber is value of my lookup field.
I skipped ForEach for Item's attachments since earlier I force user to keep only one attachment in Child listitem.