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.