Fellows, In this blog I will let you know about how to execute data entity export job through code.
#DMF
SharedServiceUnitFileID fileId;
DMFDefinitionGroupName definitionGroupName = "MyUniqueDefinitionGroupName";
try
{
EntityName entityName = DMFEntity::findFirstByTableId(tableNum(BankPositivePayExportEntity)).EntityName;
// Start:Optional if you want to filter data while exporting
Query query = new Query(DMFUtil::getDefaultQueryForEntity(entityName));
QueryBuildDataSource qbds = query.dataSourceTable(tableNum(BankPositivePayExportEntity));
SysQuery::findOrCreateRange(qbds, fieldNum(BankPositivePayExportEntity, PositivePayNumber)).value(bankPositivePayTable.PositivePayNum);
// End
DMFEntityExporter exporter = new DMFEntityExporter();
fileId = exporter.exportToFile(entityName,
definitionGroupName,
'1234567890', //Optional: ExecutionID
"XML-Attribute", //Optional::SourceName
#FieldGroupName_AllFields, //Optional field selection
query.pack(), //Optional: Filtered Query
curExt() //Optional: DataAReaId
);
if (fileId != '')
{
str downloadUrl = DMFDataPopulation::getAzureBlobReadUrl(str2Guid(fileId));
System.Uri uri = new System.Uri(_sourcefile);
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");
}
}
catch
{
error("error occurred while exporting");
}
That's it,
Hope it helps.
*This post is locked for comments