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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Provide an option to upload image for a record in D365 F&O using classes

(1) ShareShare
ReportReport
Posted on by 634
Hi Experts, 

I need to provide an option to upload image for some table records in a form. I followed the below link to achieve the same but it gives me an error saying Object reference not set to an object. Can anyone help me to find what is wrong in the code or is there any simple way to get it done.  
 
 
I believe the parameters are not being passed properly in the below code. can anyone help me to fix it please. 
 
internal final class uploadImage
{
    public void uploadImageFile(formRun _fromRun)
    {
       FormRun         visualForm;
       FileUpload      fileUploadControl;
       str             imageFilePathName;
       visualForm = classFactory::formRunClassOnClient(new Args(formstr(SysGetFileFromUser)));
       visualForm.init();
       visualForm.design().caption(/@ApplicationPlatform:GetFileImageCaption/);
       fileUploadControl = visualForm.design().controlName('FileUpload1');
       visualForm.run();
       visualForm.wait();
       FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult();
       if (fileUploadResult != null && fileUploadResult.getUploadStatus())
       {
           imageFilePathName = fileUploadResult.getDownloadUrl();
       }
       if(imageFilePathName)
       {
          formDataSource  signaturetable_dss =  _fromRun().dataSource(1) as FormDataSource;
          Signaturetable     signaturetableLoc = signaturetable_dss.cursor() as Signaturetable;  
          ttsbegin;
          signaturetableLoc.selectForUpdate(true);
          signaturetableLoc.Image =ImageReference::GetPackedBinaryData(imageFilePathName);
          signaturetableLoc.update();
          ttscommit;
       }
    }
    public static void main(Args _args)
    {
       FormRun formRun = _args.formRun();
       uploadImage object = new uploadImage();
       object.uploadImageFile(formRun);
    }
}
I have the same question (0)
  • Mohamed Amine Mahmoudi Profile Picture
    26,390 Super User 2025 Season 2 on at
    Hi @Alex,
     
    You confirm that you've created a table with a container field for the image and that the names are correct ?
    if not, I suggest you debug the image import class to see exactly where the error occurred.
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • D365  beginner Profile Picture
    634 on at
    Dear Mohamed,
     
    Thank you for the reply. Yes I created the table with container field. 
     
           FormRun formRun = _args.formRun(); this is not working it seems. is this a valid code ?
     
     
    public static void main(Args _args)
        {
           FormRun formRun = _args.formRun();
           uploadImage object = new uploadImage();
           object.uploadImageFile(formRun);
        }
  • Suggested answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    Consider whether you can't simply use document management; then you wouldn't need any development.
     
    If you want to write custom code, there is a much easier way to get an uploaded file: File::getFileFromUser(). Also, use the stream directly (openResult()) instead of the download URL.
     
    Anyway, when you get such an exception, you need to find where it's thrown. Then you can check why the object reference (such as a variable) is null instead of an actual object.
     
    (Moved from Dynamics 365 general forum.)
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    If you want to get the caller form, use _args.caller() instead of _args.formRun(). It assumes the class was called from a form (by a menu item button, most likely).
  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Hi Alex,
     
    You have the ability to attach images to records using standard functionality. Wouldn't it work for your scenario?
     
    Thanks,
    Layan Jweihan
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,390 Super User 2025 Season 2 on at
    Hi @Alex,
     
    have you created a action menu item and assign it to the button ?
    if yes make sure that the Copy caller query is set to yes 
    Best regards,
    Mohamed Amine MAHMOUDI
  • D365  beginner Profile Picture
    634 on at
    Thank you all for the inputs. All what I need is user should be able to attach image to each records in a form. the table and form are completely new and customized objects. This image needs to be printed / displayed in a SSRS report. Is it possible to achieve this by using document management ? if yes kindly let me know how to use it and bring the image in the report. Thanks.  
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    Yes, document mnagement allows you to upload an image and attach it to a record. When developing your report, you can take the image from document management.
     
    Here you can learn about document management.
  • Suggested answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Hi community member,

    Just like any standard form, you click on the "attachment icon" for the selected record



    Then you click new image



    Regarding reports, maybe check if this link helps:
    https://community.dynamics.com/forums/thread/details/?threadid=f45f4250-4979-4861-98ca-a63377d25144
    ​​​​​​​


    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    Hi,
     
    Did you try to add new field for image like person image in HcmWorker form ? This is a standard form.  You can do it on the same way and use it on your SSRS report, another example company image also.
     
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans