X++ Upload and Download file - D365 FO
class RetailSharedParameters_Eventhandlers { /// <summary> /// Event handler for the "UploadFile" button click event. /// </summary> /// <param name="sender">The form control that triggered the event.</param> /// <param name="e">Event arguments.</param> [FormControlEventHandler(formControlStr(RetailSharedParameters, UploadFile), FormControlEventType::Clicked)] public static void UploadFile_OnClicked(FormControl sender, FormControlEventArgs e) { // Get the button that triggered the event FormButtonControl callerButton = sender as FormButtonControl; // Get the form run instance FormRun form = callerButton.formRun(); // Get the data source for the RetailSharedParameters table FormDataSource RetailSharedParameters_ds = form.dataSource(formDataSourceStr(RetailSharedParameters, RetailSharedParameters)) as FormDataSource; // Get the current record from the data source RetailSharedParameters RetailSharedParameters = RetailSharedParameters_ds.cursor(); // Prompt the user to upload a file FileUploadTemporaryStorageResult result = File::GetFileFromUser() as FileUploadTemporaryStorageResult; // Check if the file upload was successful if (result && result.getUploadStatus()) { // Store the file name and download URL in the table RetailSharedParameters.FileName = result.getFileName(); RetailSharedParameters.SoundFile = result.getDownloadUrl(); // Save the changes to the database RetailSharedParameters.write(); } } /// <summary> /// Event handler for the "DownloadFile" button click event. /// </summary> /// <param name="sender">The form control that triggered the event.</param> /// <param name="e">Event arguments.</param> [FormControlEventHandler(formControlStr(RetailSharedParameters, DownloadFile), FormControlEventType::Clicked)] public static void DownloadFile_OnClicked(FormControl sender, FormControlEventArgs e) { // Variable to store the file URL str fileUrl = ''; // Get the button that triggered the event FormButtonControl callerButton = sender as FormButtonControl; // Get the form run instance FormRun form = callerButton.formRun(); // Get the data source for the RetailSharedParameters table FormDataSource RetailSharedParameters_ds = form.dataSource(formDataSourceStr(RetailSharedParameters, RetailSharedParameters)) as FormDataSource; // Get the current record from the data source RetailSharedParameters RetailSharedParameters = RetailSharedParameters_ds.cursor(); // Retrieve the stored file URL fileUrl = RetailSharedParameters.SoundFile; // Open the file URL in a browser if (fileUrl) { new Browser().navigate(fileUrl); } else { // Notify the user if no file URL is found warning("No file URL found."); } } }
Published on:
Learn moreRelated posts
Simplifying License Management for Dynamics 365 Finance and Operations: Improved User License Validation
Microsoft is updating the timeline for in-app notifications and per-user license validation to give customers more time to prepare. To enable ...
Simplifying License Management for Dynamics 365 Finance and Operations: Improved User License Validation
In-product notifications and user subscription license (USL) validation has been amended for customers in FY25 Q4, FY26 Q1 renewals. Microsoft...
D365FO Integration: Import Purchase Orders from PDF using Gemini AI
Learn how to use AI to import purchase orders into Dynamics 365 Finance from complex PDF files. This post covers integration design, sample pr...
Create X++ Client Plugins for Copilot Studio in Dynamics 365 F&O
Part 3 of the Copilot Studio + F&O extensibility series. Learn what client plugins are, when to use them, and how to build one in X++—fro...
Build an X++ AI Tool for Copilot Studio in Dynamics 365 F&O
Learn how to wire real F&O business logic into Copilot Studio. This guide shows you how to build an X++ AI tool, set up security, auto/ha...
Microsoft Dataverse – Copilot support for finance and operations development
We are announcing Copilot support for finance and operations development in Microsoft Dataverse. This feature will reach general availability ...
Copilot Studio 101: Extend Dynamics 365 F&O Copilots
Kick off a hands-on series on Copilot Studio for Dynamics 365 F&O. See what it is, the setup you need, how it uses Dataverse, built-in co...
New Feature in Dynamics 365 F&O 10.0.45 Preview: Customer Invoice Logging and Traceability Framework
Have you been posting Sales Order Invoices and Customer Free Text Invoices through batch jobs, only to struggle with tracking the status of th...
Part-10: Create your Custom Agent for D365 F&O[Chart of Account Agent]
Enough talk. Let’s see Copilot Studio in action. Over the weekend, I built something powerful – a custom AI agent for Microsoft Dynamics 365 F...
New Approved Customer List mapping for Items in Dynamics 365 Finance and operations
Take control of your sales process with the latest feature in Microsoft Dynamics 365 Finance – the Approved Customer List! This powerful new f...