Tuesday, 26 June 2018

Code to execute DMF through Code

Move Data from File to staging :

 Void fileToDMStaging()
    {
       
        DMFDefinitionGroupExecution     groupExecution;
        DMFDefinitionGroupEntity    dMFDefinitionGroupEntity;
        definitionGroup = DMFDefinitionGroup::find(CustParameters::find().CITImportProject); 
// Field of Extended Data type : "DMFDefinitionGroupName" Created in CustParameters which //should be selected . - Process group created can be shown in this field.

        executionId             = DMFUtil::generateExecutionId(CustParameters::find().CITImportProject);
        Description description = strFmt('Execution - %1 for Definition Group - %2', executionId, CustParameters::find().CITImportProject);
        DMFDefinitionGroupExecution::insertOrDisplay(definitionGroup, executionId, description, false);
        select entity from dMFDefinitionGroupEntity where dMFDefinitionGroupEntity.DefinitionGroup == definitionGroup.DefinitionGroupName;
        ttsbegin;
        groupExecution = DMFDefinitionGroupExecution::find(definitionGroup.DefinitionGroupName,dMFDefinitionGroupEntity.Entity,executionId,true);

// Below code is written , as it takes filepath set to process group instead we need to use contract //parameter file path :

        groupExecution.FilePath = /*"C4PCUATTF";*/filePath;
        groupExecution.FilePath = groupExecution.applyTransforms(groupExecution.FilePath);
       
        groupExecution.ExcelLookUp =
                        DMFDefinitionGroupEntity::insertExcelLookUpValue(
                        groupExecution.DefinitionGroup,
                        groupExecution.Entity,
                        groupExecution.FilePath,
                        groupExecution.Source);
        groupExecution.update();
        ttscommit;
        DMFStagingWriterContract        contract = new DMFStagingWriterContract();
        DMFQuickImportExport::doPGImport(definitionGroup.DefinitionGroupName ,executionId);//Need to create extension of class DMFQuickImportExport to pass File path and assign it to the contract variable
    }


Move Data from Staging to Target :

 Void stagingToTarget()
        {
            DmfDefinitionGroupExecution dmfDefinitionGroupExecution;
            dmfDefinitionGroupExecution=dmfDefinitionGroupExecution::find(CustParameters::find().CITImportProject,'Customer payment journal line',executionId);
            if (dmfDefinitionGroupExecution.ExecutionId)
            {
                ttsbegin;
                DMFDefinitionGroupExecution defGroupExec;

                update_recordset defGroupExec
                setting IsSelected = NoYes::yes,
                    ExecuteTargetStep = NoYes::Yes
                where defGroupExec.ExecutionId == DMFDefinitionGroupExecution.ExecutionId;

                ttscommit;
            }

            DMFentitywriter  Dmfentitywriter = new DMFentitywriter();
            Dmfentitywriter.parmEntityTableName('CustomerPaymentJournalLineStaging');
            Dmfentitywriter.parmDMFExecution(DMFExecution::find(executionId));
            Dmfentitywriter.parmDMFDefinitionGroupExecution(dmfDefinitionGroupExecution);
            Dmfentitywriter.parmExecutionId(executionId);
            Dmfentitywriter.run();
           
        }

No comments:

Post a Comment