Friday, August 27, 2021

DMF import records for multiple companies

 Say, we need to import Bank reconciliation records from an Excel file for many target companies at once.

The standard DMF approach does not allow to do so via DMF data entities out of the box.

However, we can easily customize Data Entity copyCustomStagingToTarget method to loop through all companies encountered in an imported file lines.

/// <summary>
    /// Performs a custom copy from the staging table to the target environment.
    /// </summary>
    /// <param name = "_dmfDefinitionGroupExecution">The definition group.</param>
    /// <returns>A container of counts of [new records, updated records].</returns>
    /// <remarks>
    /// When doing set-based inserts, the full defaulting logic from LedgerJournalTrans is not
    /// run. In order to get full defaulting, row-by-row processing must be performed. Since
    /// this method is called specifically from the DIXF framework, the entity in
    /// DIXF can be marked as AllowSetBased=False in order to force row-by-row defaulting
    /// and validation. The trade off is a significant degradation in copy performance.
    /// </remarks>
    public static container copyCustomStagingToTarget(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution)
        CDPBankReconStaging     staging;
        Set                     companySet;
        DMFStagingValidationLog log;

        delete_from log
            log.DefinitionGroupName == _dmfDefinitionGroupExecution.DefinitionGroup && 
            log.ExecutionId         == _dmfDefinitionGroupExecution.ExecutionId;

        update_recordset staging setting TransferStatus = DMFTransferStatus::NotStarted
            staging.TransferStatus  == DMFTransferStatus::Validated &&
                staging.DefinitionGroup == _dmfDefinitionGroupExecution.DefinitionGroup &&
                staging.ExecutionId     == _dmfDefinitionGroupExecution.ExecutionId;

        int64 updatedRecords = 0;
        int64 newRecords = 0;
        // Validating companies
        // Getting the company list to loop through
        companySet = CDPBankReconDE_Helper::getStagingCompanySet(_dmfDefinitionGroupExecution);

        // the party begins here!
        SetEnumerator se = companySet.getEnumerator();
        while (se.MoveNext())
            SelectableDataArea currCompany = se.current();

                CDPBankReconDE_Helper::validateTransactionCurrency(currCompany, _dmfDefinitionGroupExecution);
                // do any other necessary logic
                newRecords += CDPBankReconDE_Helper::createBankAccountTransactions(currCompany, _dmfDefinitionGroupExecution);
                // making DMF happy
                CDPBankReconDE_Helper::updateStagingTransferStatusToCompleted(currCompany, _dmfDefinitionGroupExecution);

                // Posting
                CDPBankReconDE_Helper::reconcileAccountStatement(currCompany, _dmfDefinitionGroupExecution);

        return [newRecords, updatedRecords];

Getting company list

/// <summary>
    /// gets a set of all legal entities present in the staging
    /// </summary>
    /// <param name = "_dmfDefinitionGroupExecution"></param>
    /// <returns></returns>
    public static Set getStagingCompanySet(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution)
        CDPBankReconStaging staging;
        Set companySet = new Set(Types::String);
        while select CDPCompany from staging
            group by CDPCompany
             staging.DefinitionGroup == _dmfDefinitionGroupExecution.DefinitionGroup &&
             staging.ExecutionId     == _dmfDefinitionGroupExecution.ExecutionId &&
            (staging.TransferStatus == DMFTransferStatus::NotStarted || staging.TransferStatus == DMFTransferStatus::Validated)
        return companySet;

No comments: