Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 175888

How to use DMFStagingToSourceFileWriter class to write from staging table to file

$
0
0

Hi,

I'm trying to do a batch that populate  staging table  from ax and  export data from staging table  to file at the one time. Here i'm started and my batch can populate data into staging table ,now i have some difficulty to export this data to the file,

The following method  is run on my batch :

public void run()
{
DMFDefinitionGroup definitionGroup;//nom proccessing group
DMFDefinitionGroupEntity definitionGroupEntity;
DMFEntity dMFEntity,localEntity;
DMFExecutionId executionId;//nom job
boolean execute;
DMFDefinitionGroupExecution definitionGroupExecution;
DMFStagingWriter stagingWriter;
DMFVendPackingSlipTrans vendPackingSlipTrans;
DMFVendPackingSlipTransDetails vendPackingSlipTransDetails;

DMFEntityType dmfEntityType ;
DMFdefinationGroupName definationGroupName;
DMFDataSourceProperties dataSourceProperties;
DMFSourceName source;
FilenameSave filePath;
str headerRow;
DMFStagingToSourceFileWriter dmfStagingToSourceFileWriter;


select firstOnly definitionGroup
join definitionGroupEntity
where definitionGroup.DefinationGroupName == definitionGroupEntity.DefinitionGroup
join dMFEntity
where definitionGroupEntity.Entity == dMFEntity.EntityName
&& dMFEntity.EntityName == "sauVendPackingSlipTrans"
&& definitionGroup.DefinationGroupName == "VendPackingSlipTransAx";


select firstonly vendPackingSlipTransDetails
join vendPackingSlipTrans
where vendPackingSlipTransDetails.DMFVendPackingSlipTrans == vendPackingSlipTrans.RecId ;

executionId = this.getExecutionMethod(definitionGroup.DefinationGroupName);//name proccessing group

// if no file set, then use repository mode
if(!fileName)
{
execute = DMFDefinitionGroupExecution::serviceInsertOrDisplay( definitionGroup,executionId,dMFEntity.EntityName,'','',vendPackingSlipTransDetails.ProcessingFolder,vendPackingSlipTransDetails.CompletedFolder,vendPackingSlipTransDetails.ErrorFolder,NoYes::Yes,DMFFileType::File,1,vendPackingSlipTransDetails.AccessFolder);
}
// else use file mode
else
{
execute = DMFDefinitionGroupExecution::insertOrDisplay( definitionGroup,executionId,'',NoYes::No,fileName);
}
definitionGroupExecution = DMFDefinitionGroupExecution::find(definitionGroup.DefinationGroupName,dMFEntity.EntityName,executionId)

if(execute)
{
ttsBegin;
definitionGroupExecution.selectForUpdate(true);
definitionGroupExecution.ExecuteTargetStep = NoYes::Yes;
definitionGroupExecution.Update();
ttsCommit;

//populate staging table : stagingWritting
stagingWriter = new DMFStagingWriter();
stagingWriter.parmDMFExecution(DMFExecution::find(executionId));
stagingWriter.parmcalledFrom(true);
stagingWriter.parmInBatch(this.isInBatch());
if(!fileName)
stagingWriter.sauParmRunOnService(true);
stagingWriter.run();

// Write from Staging table to file

definationGroupName = vendPackingSlipTransDetails.StaggingToFileDefGrp;

select firstOnly definitionGroupEntity
where definitionGroupEntity.DefinitionGroup == definationGroupName;

// check if definition group exists
if(!definitionGroupEntity.DefinitionGroup)
throw error(strFmt("Le groupe de traitement %1 n'existe pas", definationGroupName));

source = definitionGroupEntity.Source;
// if file name correctly set (mandatory)
if(vendPackingSlipTransDetails.Export_Prefix && vendPackingSlipTransDetails.Export_FileExtension)
{
//filePath = FolderPath + fileName + date + extension;
filePath = strFmt("%1%2_%3", vendPackingSlipTransDetails.FolderPath,
vendPackingSlipTransDetails.Export_Prefix,
vendPackingSlipTransDetails.Export_FileExtension);

// set first line if required
if(vendPackingSlipTransDetails.ExportFileHeader)
headerRow = this.setHeaderRow(dataSourceProperties.FileColumnDelimiter, vendPackingSlipTransDetails.Export_Prefix);
}
else
throw error(strFmt("Le préfix doit être renseigné dans le paramétrage d'export de l'entité %1", entityType));

// Shared folder has to be set
if (!DMFParameters::find().SharedFolderPath)
throw error("@DMF1444");

// Shared folder has to be accessible
if (DMFParameters::find().ValidationStatus != NoYesError::Yes)
throw error("@DMF1415");

// export to file
dmfStagingToSourceFileWriter = DMFStagingToSourceFileWriter::construct();
dmfStagingToSourceFileWriter.parmsourceTarget(DMFSourceTarget::Source);
dmfStagingToSourceFileWriter.parmEntityName(definitionGroupExecution.Entity);
dmfStagingToSourceFileWriter.parmDefinitionGroupExecution(definitionGroupExecution);
dmfStagingToSourceFileWriter.sauParmDMFEntityType(DMFEntity::find(definitionGroupExecution.Entity).Type);
dmfStagingToSourceFileWriter.sauparmHeaderRow(headerRow);
dmfStagingToSourceFileWriter.saveLast();
dmfStagingToSourceFileWriter.sauVariablesSetter([definationGroupName,source,filePath]);
dmfStagingToSourceFileWriter.run();
//dmfStagingToSourceFileWriter.exportRun();
}
}
}


Viewing all articles
Browse latest Browse all 175888

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>