Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

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

(1) ShareShare
ReportReport
Posted on by 5,935
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:
  • @rp@n Profile Picture
    @rp@n 5,935 on at
    I like to export Vendor master data through DMF data project using X++
    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. 
     
     
  • @rp@n Profile Picture
    @rp@n 5,935 on at
    I like to export Vendor master data through DMF data project using X++
    Thanks Martin for the response 
     
    Will update the same, if I faced any issue.
  • Martin Dráb Profile Picture
    Martin Dráb 230,407 Most Valuable Professional on at
    I like to export Vendor master data through DMF data project using X++
    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
    @rp@n 5,935 on at
    I like to export Vendor master data through DMF data project using X++
    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 
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 9,782 Super User 2024 Season 2 on at
    I like to export Vendor master data through DMF data project using X++
    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,374 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans