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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

I like to export Vendor master data through DMF data project using X++

(2) ShareShare
ReportReport
Posted on by 56
Hi All,
 
I like to Export Vendor master data through DMF data project using X++.
 
I mean, end user like to click on menu item, then it should generate a data project for Vendor and from there they will download the excel file.
 
theses entire process needs to do in code.
 
can anyone please give me a reference please.
 
Thanks!
Categories:
I have the same question (0)
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,801 Super User 2026 Season 1 on at
    Hi @@rp@n,
     
    Functionally, you can export the list of suppliers without using x++ code.
     
     
    If you insist on doing it in the x++ code, you can refer to this link.
     
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • @rp@n Profile Picture
    56 on at
    Thanks Mohamed,
     
    One thing I forgot to tell. When execution is completed, the data project should download in local machine under download folder.
     
    From there they will take the data project and excel file to proceed further.
     
    How I can do the same through x++ while exporting the customer.
     
    Kindly advise please 
  • Martin Dráb Profile Picture
    239,035 Most Valuable Professional on at
    X++ code runs on a web server in Azure and it can't connect to users' machines and meddle with their files.
     
    What you could do is to give users the file for download (with File::sendFileToUser()) and if they have their browsers configured to automatically download files to the Download folder, it'll happen.
     
    Or you'll need a completely different architecture, e.g. saving the file to Azure file share (that users may have mapped as a drive), using Recurring Integration Scheduler running in user's local network or something.
  • @rp@n Profile Picture
    56 on at
    Thanks Martin for the response 
     
    Will update the same, if I faced any issue.
  • @rp@n Profile Picture
    56 on at
    Hi Martin , Mohamed
     
    Can I use the below code for my requirement 

    It is customer master but I like to use for Vendor 
     
    class CustomerMasterExportJob
    {
        public static void main(Args _args)
        {
            DataManagementDefinitionGroupExecution definitionGroupExecution;
            DataManagementDefinitionGroupEntity definitionGroupEntity;
            DMFDefinitionGroup definitionGroup;
            DataProjectExecutionId executionId;
            DataProjectName projectName = 'CustomerMasterExportProject';
            DataEntityName entityName = 'CustCustomerDataStorageEntity'; // Entity name for export
            Filename filePath, fileName;
            Container fileContents;
            try
            {
                // Step 1: Create a new Data Project
                ttsBegin;
                definitionGroup = DMFDefinitionGroup::construct();
                definitionGroup.DefinitionGroupName = projectName;
                definitionGroup.Description = "Customer Master Export Project";
                definitionGroup.IsShared = NoYes::No; // Private to the environment
                definitionGroup.insert();
     
                // Step 2: Add entity to the project
                definitionGroupEntity = DMFDefinitionGroupEntity::construct(definitionGroup.DefinitionGroupName, entityName);
                definitionGroupEntity.InsertSeq = 1;
                definitionGroupEntity.TargetEntityName = entityName;
                definitionGroupEntity.insert();
                ttsCommit;
     
                // Step 3: Execute the data export
                executionId = DMFExecutionHelper::generateExecutionId();
                definitionGroupExecution = DataManagementDefinitionGroupExecution::construct();
                definitionGroupExecution.run(projectName, executionId, DataManagementTaskExecutionMode::Sequential, null);
                // Wait for completion
                while (!definitionGroupExecution.isExecutionCompleted())
                {
                    pause(2000); // Check every 2 seconds
                }
     
                // Step 4: Generate the export file
                filePath = DataManagementDefinitionGroupExecution::generateExportFile(definitionGroup.DefinitionGroupName, executionId);
                
                if (filePath)
                {
                    // Step 5: Read the file contents
                    fileContents = SysOperationStorage::getFile(filePath);
     
                    // Step 6: Send the file to the user for download
                    fileName = 'CustomerMasterData.zip'; // Desired file name
                    File::SendFileToUser(fileContents, fileName, "application/zip");
                    info("Export file has been downloaded successfully.");
                }
                else
                {
                    error("Failed to generate the export file.");
                }
            }
            catch (Exception::Error)
            {
                error("An error occurred during the export process: " + AifUtil::getErrorMessage());
            }
        }
    }
     
     
    Note - Not yet executed the code. 
     
     
  • Martin Dráb Profile Picture
    239,035 Most Valuable Professional on at
    In your other thread (Parameter need to pass on data entity in d365fo), I already told you about standard code for this purpose: DMFEntityExporter.exportToFile(). But you said you wanted something manual instead. Now it seems that you want the same thing after all and you forgot my answer.

    Obviously, you must use an entity for vendors (e.g. VendVendorV2Entity) instead of CustCustomerDataStorageEntity.
  • @rp@n Profile Picture
    56 on at
    class UCL_DataProject
    {
        public static void main(Args  _args)
        {
            
                    #DMF
                    SharedServiceUnitFileID fileId;
                    DMFDefinitionGroupName definitionGroupName = "CustomerAgingDataStorage";
     
                    try
                    {
                        EntityName  entityName = DMFEntity::findFirstByTableId(tableNum(CustomerAgingDataStorageEntity)).EntityName;
     
                        // Start:Optional if you want to filter data while exporting
                        //Query   query = new Query(DMFUtil::getDefaultQueryForEntityV3(entityName));
                        //QueryBuildDataSource qbds = query.dataSourceTable(tableNum(CustAgingDataHeaderStorage));
                        //SysQuery::findOrCreateRange(qbds, fieldNum(CustAgingDataHeaderStorage, BatchName)).value("30.09-2024-10-29T16:37:38");
                        // End
     
                        DMFEntityExporter exporter = new DMFEntityExporter();
                        fileId = exporter.exportToFile(entityName,
                        definitionGroupName,'',"Excel","@ApplicationFoundation:DMFExportOperation",query.pack(),curext()
                        );
     
                        if (fileId != '')
                        {
                            str downloadUrl = DMFDataPopulation::getAzureBlobReadUrl(str2Guid(fileId));
     
                            System.Uri uri = new System.Uri(downloadUrl);
                            str fileExt;
     
                            if (uri != null)
                            {
                                fileExt = System.IO.Path::GetExtension(uri.LocalPath);
                            }
     
                            Filename filename = strFmt('MyFirstExport%1',fileExt);
                            System.IO.Stream stream = File::UseFileFromURL(downloadUrl);
                            File::SendFileToUser(stream, filename);
                        }
                        else
                        {
                            throw error("DMF execution failed and details were written to the execution log");
                        }
                        info("Export had been done successfully");
                    }
                    catch
                    {
                        error("error occurred while exporting");
                    }
        }
    
    }
    Hi Martin,
     
    2. When they select any batch from the form "Customer Aging Data Storage, I need to pass a parameter "batch" from the button to this class. So, that I can filter the data before exporting to excel based on the batch number.    But the I query for testing with hardcore Batch number" is not working. And it's exported all data.
     
    3. As per my code, If any error occurred during the exportation, is it captured in the Execution LOG? as per standard behavior.
     
    4. Now the excel file is downloaded to the local machine in the Download folder perfectly.
     
    5. But the customer is looking for the file as a data project after downloading in the local machine in download folder as below:

    In the below format customer looking for the excel file:



     
    Kindly let me know what modifications is required.
     
    Thanks!
  • Martin Dráb Profile Picture
    239,035 Most Valuable Professional on at
    2. Your code won't compile at all and and it's for a wrong entity (this thread is about "Export Vendor master data"). If you have a question not belonging to this thread, use or create another thread. If it belongs here, give us the correct code. 
    3. Yes.
    5. You've exported a package. I guess that's how you've configured the export project.
  • @rp@n Profile Picture
    56 on at
    Sure, Martin I will post in new thread soon. Thanks!
  • Martin Dráb Profile Picture
    239,035 Most Valuable Professional on at
    @@rp@n I see you've created a similar thread, Entity export through X++. Do you still want to discuss something in this thread, or is it now obsolete?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 468 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans