Get number of attachments with document using X++
It is really tricky and difficult to get number of attachments with document using X++ in Microsoft Dynamics 365 for Finance and Operations. I will explain and share the code which will help you in achieving the results.
Attachments are very useful to store all the necessary information related to the document. You can attach a file, image, URL or note to a document as a physical attachment.
In Picture 1.1, you can see that 0 attachments are there with the General Journal USMF-000000003. When you click on the attachment button, an attachment form will be opened, which you can see in the Picture 1.2.
According to the Picture 1.2, there is 0 attachment with the document. So, when you will run the code, you will get 0 as a result.
How to get number of attachments with document using X++?
- Create a Runnable Class (Job)
- Paste the code in main function
- Replace the code where necessary as per your requirements
- Execute the Job
//Moeen Ahmed Sultan //WhatsApp: +92 321 458 9595 //Code is used to get the number of attachments with the document. In this code, we are checking that how many attachments are with the Journal. //If you want to check it with any other document, you need to replace the LedgerJournalTable with the document's table. DocuRef docuRef; DocuValue docuValue; LedgerJournalTable ledgerJournalTable; //You can use other tables as per your requirements select * from ledgerJournalTable where LedgerJournalTable.JournalNum == 'USMF-000000003'; //Replace <LedgerJournalTable> with your <table name> //Counting total attachments with the current record/document select count(RecId) from docuRef where docuRef.RefRecId == ledgerJournalTable.RecId && docuRef.RefTableId == tableNum(LedgerJournalTable) && docuRef.RefCompanyId == curExt(); info(strFmt("%1", docuRef.RecId));
So, in this way you can get number of attachments with document in D365FO using x++. Moreover, if this helps you, please Like, Comment and Share to help other people.
Additionally, If you found any ambiguity or a better solution, please feel free to ask.
Download code: Click here
Blog: Click here
YouTube: Click here
GitHub: Click here
Opportunities don’t happen. You create them. – Chris Grosser