Forum Discussion
Get attachment link from SP List Attachment column
- Anonymous1 year ago
Hi nok , hello MattiaFratello, thank you for your prompt reply!
Create a new blank query and paste the following M code to meet your requirement:
let SharePointSiteURL = "YourSharePointSiteUrl", SharePointTenant="https://Yourtenantname.sharepoint.com", API_URL = SharePointSiteURL & "/_api/web/lists/getbytitle('YourListName')/items?$expand=AttachmentFiles", Source = Json.Document(Web.Contents(API_URL, [Headers=[#"Accept"="application/json;odata=nometadata"]])), ListItems = Source[value], ExpandedItems = Table.ExpandRecordColumn(Table.FromList(ListItems, Splitter.SplitByNothing()), "Column1", {"ID", "Title", "AttachmentFiles"}), ExpandedAttachments = Table.ExpandListColumn(ExpandedItems, "AttachmentFiles"), AttachmentUrls = Table.ExpandRecordColumn(ExpandedAttachments, "AttachmentFiles", {"ServerRelativeUrl"}), FinalTable = Table.AddColumn(AttachmentUrls, "AttachmentLink", each SharePointTenant & [ServerRelativeUrl], type text), ResultTable = Table.SelectColumns(FinalTable, {"ID", "Title", "AttachmentLink"}) in ResultTableRemember to cahnge the
siteurl,tenantname, andlistnameto your specific valuesAfter that, format the text in the column as a web URL:
My sample test for your reference:
Best regards,
Joyce
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi nok , hello MattiaFratello, thank you for your prompt reply!
Create a new blank query and paste the following M code to meet your requirement:
let
SharePointSiteURL = "YourSharePointSiteUrl",
SharePointTenant="https://Yourtenantname.sharepoint.com",
API_URL = SharePointSiteURL & "/_api/web/lists/getbytitle('YourListName')/items?$expand=AttachmentFiles",
Source = Json.Document(Web.Contents(API_URL, [Headers=[#"Accept"="application/json;odata=nometadata"]])),
ListItems = Source[value],
ExpandedItems = Table.ExpandRecordColumn(Table.FromList(ListItems, Splitter.SplitByNothing()), "Column1", {"ID", "Title", "AttachmentFiles"}),
ExpandedAttachments = Table.ExpandListColumn(ExpandedItems, "AttachmentFiles"),
AttachmentUrls = Table.ExpandRecordColumn(ExpandedAttachments, "AttachmentFiles", {"ServerRelativeUrl"}),
FinalTable = Table.AddColumn(AttachmentUrls, "AttachmentLink", each SharePointTenant & [ServerRelativeUrl], type text),
ResultTable = Table.SelectColumns(FinalTable, {"ID", "Title", "AttachmentLink"})
in
ResultTable
Remember to cahnge the siteurl, tenantname, and listname to your specific values
After that, format the text in the column as a web URL:
My sample test for your reference:
Best regards,
Joyce
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.