web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

File Upload OnUploadCompleted Event

(0) ShareShare
ReportReport
Posted on by 5

I am studying D365FO. I am practicing upload files with FileUpload control. I have followed tutorials from the web. Here is the link

https://community.dynamics.com/365/financeandoperations/b/dynamics365foaxhub/posts/import-upload-data-in-d365-ax7-using-excel-file

I tried to display the test message after uploading completed but was unable to show it. Here is the sample code, which has no error but the result is not as required.

Here is the code. OK button click is working fine. But upload the complete event is not working, I need help to fix the problem

public class MyFileUploadEventHandler extends FormRun
{
    FileUploadTemporaryStorageResult fileUploadResult;
    [Form("Custom")]
    class FileUploadData
    {
        public void uploadCompleted(FormControl sender, FormControlEventArgs e)
        {
            Info("File Uploaded");
        }
    }
    [FormControlEventHandler(formControlStr (FrmUploadData,OKCommandButton), FormControlEventType::Clicked)]
    public static void OKCommandButton_OnClicked(FormControl sender, FormControlEventArgs e)
    {
            Info("Ok Clicked");
    }

}
I have the same question (0)
  • NadeemBhatti Profile Picture
    5 on at
    RE: File Upload OnUploadCompleted Event

    Hi Martin,

    It was a port issue, as I told you in an earlier post that I have changed the azure emulator ports. Because it was not working on the default ports settings. Now I have it set to default ports to check and this time it's worked.

    Then I got the reading/writing timeout exception with the .xls file but successfully read the .xlsx file.

    Thank you for your co-operation.

  • Martin Dráb Profile Picture
    236,160 Most Valuable Professional on at
    RE: File Upload OnUploadCompleted Event

    Which method at which line is throwing the error? You can see the StackTrace property of the exception to get this information.

    Also, my code calls exactly the same method as your code (this.getFileUploadResult()), but you didn't mention getting this error. Is it correct? Isn't the exception actully related to some other code than my version of OnUploadCompleted()?

  • NadeemBhatti Profile Picture
    5 on at
    RE: File Upload OnUploadCompleted Event

    Thanks, Martin,

    I have changed the code and check the value in the debugger. It returns the exception "Object reference not set to an instance of an object"

  • Martin Dráb Profile Picture
    236,160 Most Valuable Professional on at
    RE: File Upload OnUploadCompleted Event

    What if you change code in OnUploadCompleted() to this and debug it?

    public void OnUploadCompleted()
    {
        FileUploadResultBase testResult = this.getFileUploadResult();
        super();
    }

    Do you see a value (of testResult variable) in debugger?

  • NadeemBhatti Profile Picture
    5 on at
    RE: File Upload OnUploadCompleted Event

    Thanks, Martin,

    Thanks again, It helps me a lot. Now the OnUploadCompleted event is going to execute, but unfortunately, the fileUploadResult object gets nothing. So I am unable to read the excel file. I have tried to debug and try to find the uploaded file in the emulator but in vain. 

    I have used the local emulator with ports https:\\127.0.0.1:20000 to https:\\127.0.0.1:20002 as https:\\127.0.0.1:10000 was not working for me.

    Please help me, how to fix the issue. my code is here. 

    [Form]
    public class FrmUploadData extends FormRun
    {
        FileUploadTemporaryStorageResult	fileUploadResult;
        
    
        [Control("Custom")]
        class FileUpload1
        {
            public void OnUploadCompleted()
            {
                fileUploadResult = this.getFileUploadResult() as FileUploadTemporaryStorageResult;
                super();
            }
    
        }
    
        [Control("Button")]
        class OKCommandButton
        {
            public void clicked()
            {
                MenuFunction uploadMenuFunction;
                Args 		args = new Args();
       
                super();
                if(fileUploadResult != null && fileUploadResult.getUploadStatus())
                {
                    Args.parmObject(fileUploadResult);
                    uploadMenuFunction 	= new MenuFunction(identifierStr("MnuUploadData"), MenuItemType::Action);
                    uploadMenuFunction.run(Args);
                }
    
    
            }
    
        }
    
    }

  • Verified answer
    Martin Dráb Profile Picture
    236,160 Most Valuable Professional on at
    RE: File Upload OnUploadCompleted Event

    The first one is used in the blog post you've linked above.

    If you want to use an event, you need to subscribe to it. For example, this is how you can do it in X :

    uploadControl.notifyUploadCompleted  =  eventhandler(this.UploadCompleted);

    You can find an example in Images on a page or in a grid, or simply search either the application or internet for more example.

  • NadeemBhatti Profile Picture
    5 on at
    RE: File Upload OnUploadCompleted Event

    Hi Martin

    Thanks for your reply, as I am learning can you give me references to try both methods to try.

  • Martin Dráb Profile Picture
    236,160 Most Valuable Professional on at
    RE: File Upload OnUploadCompleted Event D365FO

    The blog post talks about overriding OnUploadCompleted(), but that's not what you did. It seems that you copied an event handler method from somewhere else and you didn't create an event subscription to call this method. Therefore you just have a new method that isn't ever called.

    You need to decide if you want to override a system method or subscribe to an event.

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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,370

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 848 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 675 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans