Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Blogs / ShabibAX / Export data entity through ...

Export data entity through code Dynamics 365 Finance and Operations X++

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.

Comments

*This post is locked for comments

  • Shailee Shah Profile Picture Shailee Shah 80
    Posted at
    Export data entity through code Dynamics 365 Finance and Operations X++
    If you want to dynamically filter your records then make sure to have dynamic definition group name logic in place. Standard code will not add filter to your existing DMF project.
  • Preetham Profile Picture Preetham 85
    Posted at
    Any luck with applying ranges? Having similar requirement
  • Harika Profile Picture Harika 40
    Posted at
    Hi Shabib, I am using the same code to export the Sales order through X++. I am able to export all the sales orders but could not apply range to it and export particular sales orders. Can you please help me how can i achieve it