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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Export data through DMF data project using x++ query range is not working

(0) ShareShare
ReportReport
Posted on by 47

Hi,

Using the following code to generate CSV file by Data entity through x++ code.

I am getting the CSV file with all data, filter query range is not working.

Please help me on this. 

public void exportHeader()
{
#DMF
SharedServiceUnitFileID fileId;
DMFDefinitionGroupName definitionGroupName = #AgHdExp;

try
{
EntityName entityName = DMFEntity::findFirstByTableId(tableNum(SalesAgreementHeaderEntity)).EntityName;

// Start:Optional if you want to filter data while exporting
Query query = new Query(DMFUtil::getDefaultQueryForEntityV3(entityName));
QueryBuildDataSource qbds = query.dataSourceTable(tableNum(SalesAgreementHeaderEntity));

// query range 

SysQuery::findOrCreateRange(qbds, fieldNum(SalesAgreementHeaderEntity,
SALESAGREEMENTID)).value("LS16-000021");

// End

DMFEntityExporter exporter = new DMFEntityExporter();

fileId = exporter.exportToFile(entityName,
definitionGroupName,'',#CSV,#FieldGroupName_AllFields,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(#AgHdExp+'%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");
}
}

Thanks,

Arun

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Your code is difficult to read, because you pasted it in a wrong way and line indentation got lost. Please always use Insert > Code (in the rich-formatting view).

    public void exportHeader()
    {
        #DMF
        SharedServiceUnitFileID fileId;
        DMFDefinitionGroupName definitionGroupName = #AgHdExp;
    
        try
        {
            EntityName entityName = DMFEntity::findFirstByTableId(tableNum(SalesAgreementHeaderEntity)).EntityName;
    
            // Start:Optional if you want to filter data while exporting
            Query query = new Query(DMFUtil::getDefaultQueryForEntityV3(entityName));
            QueryBuildDataSource qbds = query.dataSourceTable(tableNum(SalesAgreementHeaderEntity));
    
            // query range 
            SysQuery::findOrCreateRange(qbds, fieldNum(SalesAgreementHeaderEntity, SalesAgreementId)).value(queryValue("LS16-000021"));
    
            // End
            DMFEntityExporter exporter = new DMFEntityExporter();
    
            fileId = exporter.exportToFile(entityName, definitionGroupName, '', #CSV, #FieldGroupName_AllFields, 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(#AgHdExp '%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");
        }
    }

    What if you run the query by yourself, instead of sending it to exportToFile(). Does it give you the right result?

  • Verified answer
    ArunAnandK Profile Picture
    47 on at

    Hi Martin,

    Thanks for the response.

    When i ran a query, i was getting proper filtered data. when i sent exportToFile() i was getting full data.

    My problem is fixed, i have added filter criteria in entity range, it works.

    Thanks,

    Arun.

  • CU02011137-0 Profile Picture
    4 on at
    Hi Arun, as you mentioned that your issue has been resolved.
     
    I have also faced the similar issue. Through exporttofile, I am getting all the data in exporting but the range is not working.
     
    Kindly send me the latest code which you used and you mentioned that range yiu provide in entity.
     
    Please send me the screenshot pls.
     
    I will follow the same.
     
    Thanks in advance!
     
    Waiting for your reply.
  • CU02011137-0 Profile Picture
    4 on at
    Can anybody pls reply on thid

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans