1

I'm stuck on creating a batch job that has two tasks -- one for getting data from staging table and another for exporting teh data from staging table to a flat file.

The first task requires that I invoke DMFStagingWriter class and it' work fine, my batch can populate data into staging table. However, when I try to add some code to complete the second task invoked by dmfStagingToSourceFileWriter class and i could't for the moment. I have a part started by this comment "// Write from Staging table to file" on my code and there i have difficulty to write the correct code whitch help me to export data from staging table to file

What am I missing?

Thank you.

public void run()
    {
        DMFDefinitionGroup                      definitionGroup;//nom proccessing group
        DMFDefinitionGroupEntity                definitionGroupEntity;
        DMFEntity                               dMFEntity,localEntity;
        DMFExecutionId                          executionId;//nom  job
        boolean                                 execute;
        DMFDefinitionGroupExecution             definitionGroupExecution;
        DMFStagingWriter                        stagingWriter;
        SAUDMFVendPackingSlipTrans              vendPackingSlipTrans;
        SAUDMFVendPackingSlipTransDetails       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.SAUDMFVendPackingSlipTrans == vendPackingSlipTrans.RecId ;

        executionId                 = this.getExecutionMethod(definitionGroup.DefinationGroupName);//nom 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;

            //Write from ax to 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;//vendPackingSlipTrans_file
            // if file name correctly set (mandatory)
            if(vendPackingSlipTransDetails.Export_Prefix && vendPackingSlipTransDetails.Export_FileExtension)
            {
                //filePath =  FolderPath + prefixfileName + grpAx + extension;
                filePath = strFmt("%1%2_%3_%4", vendPackingSlipTransDetails.FolderPath,
                                                vendPackingSlipTransDetails.Export_Prefix,
                                                vendPackingSlipTransDetails.AXToStaggingDefGrp,
                                                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();

        }
    }
aschipfl
  • 33,626
  • 12
  • 54
  • 99
stoner
  • 417
  • 2
  • 12
  • 22
  • Related: [Dynamics ax2012:How to export data using Runbasebatch](http://stackoverflow.com/questions/32950361/dynamics-ax2012how-to-export-data-using-runbasebatch) – FH-Inway Oct 30 '15 at 12:03
  • Good for you. Maybe you would like to share your solution as an answer? – FH-Inway Oct 30 '15 at 17:04
  • I have not changed this method ,but i have several change on the dmfStagingToSourceFileWriter class that contain a lot of code.i'll post all change or look for to uploud xpo file here stackoverflow – stoner Oct 30 '15 at 17:45

0 Answers0