Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Customizing the document upload dialog box for attachments in D365

(0) ShareShare
ReportReport
Posted on by 25

Hello,

I have added a custom field named Type on the pop up dialog of attachments as shown below.

pastedimage1678912975434v1.png

The value that is selected in Type field, I want to concatenate it with the file name of browsed attachment before traversing to SharePoint. Like Type is Certificates and browsed file name is ABC, resulted file name stored in DocuValue table should be ABC_Certifcates and propagate that file name all the way to SharePoint. Does anyone know how to do that in X++ code.

pastedimage1678913632792v3.png

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Customizing the document upload dialog box for attachments in D365

    What about modified field of unbound control. On the modified method write code to insert unbound control value to table.

    Thanks,

    Girish S.

  • FaranBaig Profile Picture
    FaranBaig 25 on at
    RE: Customizing the document upload dialog box for attachments in D365

    Written COC for uploadCompleted but the upload process is executed earlier and it is post notification. Tried COC for run also, but didn't worked. I'm looking for the OnUploadAttemptStarted override mentioned on Microsoft Doc. If have idea about it or some other approach to store unbound control value in table before DocumentManagement_Extension::attachFileToDocuRef(), let me know. Thanks

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Customizing the document upload dialog box for attachments in D365

    Try writing COC for uploadCompleted on the form method - On this method you can fill in the values to table from string control.

    Thanks,

    Girish S.

  • FaranBaig Profile Picture
    FaranBaig 25 on at
    RE: Customizing the document upload dialog box for attachments in D365

    I have written COC for DocumentManagement, it is the base for data traversing and working fine.

    [ExtensionOf(classStr(DocumentManagement))]
    final class DocumentManagement_Extension
    {
        public static DocuRef attachFileToDocuRef(RecId _docuRefRecId, System.IO.Stream _file, str _fileName, str _fileContentType, str _attachmentName, str _notes)
        {
            DocuRef docuRef;
            _fileName = CustomTable.field   _fileName;
            _attachmentName = CustomTable.field   _attachmentName;
            docuRef = next attachFileToDocuRef(_docuRefRecId,_file,_fileName,_fileContentType,_attachmentName,_notes);
            return docuRef;
        }
    
    }

    but closeOk is not working, even debugger did not came.I nee to fill value in table before DocumentManagement class calling.

    [ExtensionOf(formStr(DocumentUpload))]
    final class DocumentUpload_Extension
    {
        public void closeOk()
        {
    
            next closeOk();
            Formrun thisForm = this;
            Common targetRecord = thisForm.args().record();
    
            if (targetRecord && targetRecord.TableId == tableNum(DocuRef))
            {
                DocuRef docuRef = targetRecord;
                Info(strFmt("Close ok %1  %2",docuRef.RecId,docuRef.ValueRecId));
            }
        }
    
    }

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Customizing the document upload dialog box for attachments in D365

    I think you need to write COC for createFileAttachment and change the fileName there.

    For the unbound control you need to create one table and insert the value on closeOk method of DocumentUpload form. You can write COC for closeOk if it's not implemented in standard.

    Try like below.

    public void closeOk()
    {
        next closeOk();
        //create one table and insert the type value here. Delete the record in the table and reinsert them every time.
    }
    
    create extension class for DocuActionFile and add below code.
    public DocuValue createAttachmentFile(DocuRef _ref,str _fileName,str _fileContentType,System.IO.Streams _fileContents)
    {
        // add select statement to get type from newly created table and pass the fiel name to it.
        TableName tableName;
        select firstonly * from tableName;
        next createAttachmentFile(_ref,tableName.fileName   _fileName, _fileContentType,_filecontents);
    }

    I am not sure this will work but you can try as a workaround.

    Thanks,

    Girish S.

  • FaranBaig Profile Picture
    FaranBaig 25 on at
    RE: Customizing the document upload dialog box for attachments in D365

    Hi Girish S,

    I cannot COC for closeOk as it is not implemented on DocumentUpload form. moreover I write OnInserting event handler of the DocuValue table and set hard coded file name but that name did not traversed to SharePoint, I debugged and checked file name was propagated to SharePoint before DocuValue insert. See the call stack.

    DocuValue:: Insert()
    DocuActionFile::createFileAttachement()  >>> SharePoint upload at line 275
    DocuActionFile::attachFile()
    DocuActionFile::attachFile()   (here concatenated FileName needs to be send )
    DocuHistory::UpdateRecordNames (updating from DocuRef > here also concatenated FileName to be used)
    DocuRef::Update
    DocuMentManagement::attachFileToDocuRef

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Customizing the document upload dialog box for attachments in D365

    On the DocumentUpload form - Write COC for closeOk method and see whether you are getting caller record as DocuRef and see value of ValueRecId field.

    public void closeOk()
    {
        
        next closeOk();
        //check whether you are able to get DocuRef using element.args().record();
    }

    Thanks,

    Girish S.

  • FaranBaig Profile Picture
    FaranBaig 25 on at
    RE: Customizing the document upload dialog box for attachments in D365

    Hi Girish S,

    Problem is getting the value of custom field, as it is string control and its scope is within the dialog, not originating from  data source. As document upload dialog box does not have a data source. So how to achieve it?

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Customizing the document upload dialog box for attachments in D365

    Hi Faran,

    You can concatenate the File name in the OnInserting event handler of the DocuValue table.

    Thanks,

    Girish S.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans