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, ...
Unanswered

Attachment Mandatory in D365

(0) ShareShare
ReportReport
Posted on by 142

Hi

Is there a way to make an attachment mandatory based on  checkbox value if true  on save of the form?

Please share if any code snippets available

Thanks

I have the same question (0)
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    When do you want to check whether an attachment exists?

  • André Arnaud de Calavon Profile Picture
    300,911 Super User 2025 Season 2 on at

    Hi Sindhu,

    Out of the box, this is not possible. First the source record should exists before you can add attachments. You can't prevent saving the source record before you have the attachment as the attachment should have a reference to the table and the record ID.

    You can consider a customization and add a creation dialog for the source record. Then you can include a file upload. On closing the form, you can then add validations if a file was uploaded or not.

  • Vamsa Profile Picture
    142 on at

    Thanks Martin and Andre for the response. I have a customized form where the attachment is working. But only thing which need to be done is validation rule to be added for dropdown. I have  5 Checkbox ..If Check box A or Check box B or check Box C is selected then attachment to be mandatory. If Check Box D and E then attachment not needed. i am not sure whether to be written is Save or somewhere else or on click of attachment

    Thanks

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    You can't solve your problem if don't start thinking about what you actually mean by "mandatory".

    If you don't want to allow saving the source record before the related attachment exists, then this is logically wrong and it's impossible to do. The source record must exist before you can attach anything to it. Therefore you're fine with the information that the whole thing is impossible, or you'll start thinking about possible ways to solve the business problem, whatever it is.

    That you can't completely ensure that all records have an attachment doesn't mean that you can check the existence before it's really needed. For example, imagine that you're working with sales orders. You can allow them to be created without attachments, but you'll check it before invoicing.

  • Vamsa Profile Picture
    142 on at

    Hi Martin

    I have a form which the user enters the records. The form allows me to click on attachment and can add the document currently. On click of  Save, the workflow submit button appears.   Need a validation on the attachment option or submit of workflow based on check box condition. For your information, source record is saved already.  But we need to check on submit or attachment option.  Hope it is clear. Business requirement is to check whether document is attached for certain check box.

    Thanks

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    I understand that "Business requirement is to check whether document is attached", but the question is whent to check it.

    Doing it on save doesn't look correct. As already discussed, if you don't allow to save a record without an attachment, you won't be able to create a record at all. You need to create it before you can add attachments to it. And if you don't modify the record, no other saving is guaranteed to occur, therefore your check wouldn't be executed later. This design simply wouldn't work.

    Checking it before submitting to workflow seems to be what you need.

  • Vamsa Profile Picture
    142 on at

    Hi

    I already have a validation code for the following where before submit, it checks whether the checkbox is clicked or not.

    Similar way, I need to add in the same validate rule -             if (ret && DFF_GiftsTable.DFF_RetainSurrender == DFF_RetainSurrender::Retain)

    like to check if attachment exists or not. If not then validation message.

    I dont have much idea on the code to check whether the document exists or not

    public boolean validateWrite()

           {

               boolean ret;

               ret = super();

               if (ret && GiftsTable.RetainSurrender == RetainSurrender::Retain)

               {

                   if (!GiftsTable.ValuationCertificate && !GiftsTable.ChequePayableToCollector && !GiftsTable.RequestInvoice)

                   {

                      ret = checkFailed("Please complete Section 2");

                   }

               }

               else if (ret && GiftsTable.RetainSurrender == RetainSurrender::Surrender)

               {

                   if (!GiftsTable.DonateToCharity && !GiftsTable.Insert)

                   {

                       ret = checkFailed("Please complete Section 2");

                   }

               }

               return ret;

           }

    Thanks

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    It would really help if you told us more about the logic.

    As I said, submitting to workflow doesn't necessarily save a record, therefore your logic doens't have to execute at that point.

    Also, it'll be impossible to create a new record with RetainSurrender == RetainSurrender::Retain. Is it what you want? Maybe your idea is checking attachments neither on saving nor on submitting to workflow, but on changing RetainSurrender value. But who knows? We really miss the explanation from you.

    By the way, your validations seem to be implemented in a form data source. Are you completely sure that they shouldn't be placed on the table?

    And please always use Insert > Code (in the rich formatting view) to paste source code.

  • Vamsa Profile Picture
    142 on at

    Hi Martin

    Sorry that I was not clear. We have a form which is called Create Gift form where the user enters data and records gets saved. once the record gets saved, it navigated to the details form.  So I have written validation rule on the details form on data source for checking condition .Once the condition satisfies, records gets updated and workflow submit button will work.

    Similarly we need to check the validation on Retain related checkbox  whether attachment is there or not. We need to have attachment mandatory on retain related condition of all the checkbox. I am really not sure which is the best way to check that's why wrote as validationwrite and how to check whether document is there or not. Please let me know if its not clear

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    What do you mean by "validation on a checkbox"? Do you mean that you want to check something when a value of a particular field changes to a particular value? For example, a record will always be created value No and when somebody wants to update it to Yes, you'll check if an attachment exists?

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