Notifications
Announcements
No record found.
Hi everyone,
I'm working on a project in Dynamics 365 Finance and Operations (D365 FO) where I need to generate a public URL for a file stored in Azure Blob Storage, which is referenced in the DocuRef table, and then send this URL via an API. However, I'm facing issues with the URL generation part of my code. Below is the code I'm using:
class SYN_GetDatafromDocuRef { // Main method to fetch the attachment URL from the document ID public static void main(Args _args) { // DocumentId to search for DataAreaId company = "syi"; // Company ID // Call method to fetch the URL str attachmentURL = SYN_GetDatafromDocuRef::fetchAttachmentURLFromDocumentId(company); // Print the URL to the info log if (attachmentURL) { info("Attachment URL: " + attachmentURL); } else { info("No URL found for the specified document and company."); } } // Method to fetch the attachment URL from the document ID public static str fetchAttachmentURLFromDocumentId(DataAreaId _company) { DocuRef docuRef; str getURL; DocuDocumentId guid1; guid1 = Global::guidFromString("11804389-362D-400F-A0D8-C3F5B6EAA475"); try { // Query to fetch the DocuRef record select firstOnly docuRef where docuRef.DocumentId == guid1 && docuRef.ActualCompanyId == _company; // If the document record is found if (docuRef) { // Get the attachment URL by sending the file to temporary storage System.IO.Stream attachmentStream = DocumentManagement::getAttachmentStream(docuRef); str fileName = ERDocuRef_Extension::filename(docuRef); str strategyClass = classStr(FileUploadTemporaryStorageStrategy); if (attachmentStream && fileName) { getURL = File::SendFileToTempStore(attachmentStream, fileName, strategyClass, true); } else { // Handle error or log the issue throw error("Attachment stream or filename is invalid."); } return getURL; // Return the URL } else { throw error("No document found for the specified DocumentId and company."); } } catch (Exception::Error) { error("An error occurred while fetching the attachment URL."); return ""; // Return empty string if error occurs } } }
I'm trying to generate a public URL for the file stored in Blob Storage and send this URL via an API. The code for URL generation isn't working as expected. Could anyone provide guidance on how to properly generate a public URL for a file in Blob Storage and send it via an API in D365 FO?
Any help would be greatly appreciated!
Thank you for your response! To clarify, I am not getting any errors in the code, but the issue is that the generated URL is empty. My goal is to retrieve a public URL for a file stored in Azure Blob Storage, which is referenced in the DocuRef table.
I am using the File::SendFileToTempStore method to generate the URL, but it seems to return an empty value instead of a valid URL. I would appreciate any guidance on:
File::SendFileToTempStore
1.Whether my approach to retrieving the file and generating the URL is correct.
2.If there are alternative methods to generate a public URL for a document stored in Blob Storage within D365 FO.
if (fileUploadResult != null && fileUploadResult.getUploadStatus())
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 544 Most Valuable Professional
André Arnaud de Cal... 450 Super User 2025 Season 2
Sohaib Cheema 250 User Group Leader