Tuesday, April 13, 2021

How to create RunBaseBatch class in AX : Sample code

See the code

/// <summary>
///    The <c>LedgerJournalEntryPost</c> class creates and posts to general ledger transactions specified in
///    the <c>LedgerJournalEntryContract</c> contract class.
/// </summary>
class LedgerJournalEntryPost extends RunBaseBatch
{
    LedgerJournalEntryContract           ledgerJournalEntryContract;
    LedgerJournalEntryPostStatusContract ledgerJournalEntryPostStatusContract;
    Set                                     studentTransRecIdPostedSet;

    #IntegrationServiceFaults
    /// <summary>
    ///     Checks if the Ledger journal can be posted or not.
    /// </summary>
    /// <param name="_ledgerJournalTable">
    ///     Record of the <c>LedgerJournalTable</c> table to verify.
    /// </param>
    /// <returns>
    ///     True if Ledger journal can be posted; otherwise, false.
    /// </returns>
    protected boolean canPostLedgerJournal(LedgerJournalTable  _ledgerJournalTable)
    {
        LedgerJournalTrans  ledgerJournalTrans;
        VendPaymModeTable   vendPaymModeTable;
    
        select firstOnly RecId from ledgerJournalTrans
            where ledgerJournalTrans.JournalNum == _ledgerJournalTable.JournalNum;
    
        if (!ledgerJournalTrans.RecId)
        {
            return false;
        }
    
        if (_ledgerJournalTable.JournalType == LedgerJournalType::Payment)
        {
            select firstOnly RecId from ledgerJournalTrans
                where ledgerJournalTrans.JournalNum        == _ledgerJournalTable.JournalNum
                 &&   ledgerJournalTrans.AccountType       == LedgerJournalACType::Vend
                 &&   ledgerJournalTrans.OffsetAccountType == LedgerJournalACType::Bank
                 &&  (!ledgerJournalTrans.BankChequeNum
                 ||  ledgerJournalTrans.PaymentStatus      != CustVendPaymStatus::Sent)
            exists join vendPaymModeTable
                where vendPaymModeTable.PaymMode        == ledgerJournalTrans.PaymMode
                   && vendPaymModeTable.PaymentType     == PaymentType::Check;
    
            if(ledgerJournalTrans.RecId)
            {
                return false;
            }
        }
    
        return true;
    }

    /// <summary>
    ///     Creates a ledger journal for the specified ledger journal entry.
    /// </summary>
    /// <param name="_ledgerJourEntryLines">
    ///     List of <c>LedgerJournalEntryLineContract</c> contract classes.
    /// </param>
    /// <param name="_journalEntryType">
    ///     The type of the journal to create.
    /// </param>
    /// <returns>
    ///     Created <c>LedgerJournalTable</c> table.
    /// </returns>
    protected LedgerJournalTable createJournal(List                 _ledgerJourEntryLines,
                                               JournalEntryType  _journalEntryType)
    {
        LedgerJournalTable              ledgerJournalTable;
        LedgerJournalCreate          ledgerJournalCreate;
        LedgerJournalEntryContract   entryContract;
    
        entryContract = new LedgerJournalEntryContract();
        entryContract.parmLedgerJourEntryLines(_ledgerJourEntryLines);
    
        ledgerJournalCreate = LedgerJournalCreate::construct(entryContract, _journalEntryType);
        ledgerJournalCreate.run();
    
        ledgerJournalTable = ledgerJournalCreate.parmLedgerJournalTable();
    
        return  ledgerJournalTable;
    }

    /// <summary>
    ///     Finds or creates a ledger journal for the specified ledger journal entry.
    /// </summary>
    /// <param name="_ledgerJourEntryLines">
    ///     List of <c>LedgerJournalEntryLineContract</c> contract classes.
    /// </param>
    /// <param name="_journalEntryType">
    ///     The type of the journal entry.
    /// </param>
    /// <param name="_paymentType">
    ///     The payment type of the journal entry.
    /// </param>
    /// <returns>
    ///     Found or created <c>LedgerJournalTable</c> table.
    /// </returns>
    protected LedgerJournalTable findOrCreateJournal(List                 _ledgerJourEntryLines,
                                                     JournalEntryType  _journalEntryType,
                                                     SISPaymentType    _paymentType)
    {
        LedgerJournalTable  ledgerJournalTable;
    
        ledgerJournalTable = this.findRelatedJournal(_ledgerJourEntryLines, _journalEntryType, _paymentType);
    
        if (!ledgerJournalTable)
        {
            ledgerJournalTable = this.createJournal(_ledgerJourEntryLines, _journalEntryType);
        }
    
        return  ledgerJournalTable;
    }

    /// <summary>
    ///     Finds the ledger journal for the specified ledger journal entry.
    /// </summary>
    /// <param name="_ledgerJourEntryLines">
    ///     List of <c>LedgerJournalEntryLineContract</c> contract classes.
    /// </param>
    /// <param name="_journalEntryType">
    ///     The type of the journal entry.
    /// </param>
    /// <param name="_paymentType">
    ///     The payment type of the journal entry.
    /// </param>
    /// <returns>
    ///     Found <c>LedgerJournalTable</c> table.
    /// </returns>
    protected LedgerJournalTable findRelatedJournal(List                 _ledgerJourEntryLines,
                                                    JournalEntryType  _journalEntryType,
                                                    SISPaymentType    _paymentType)
    {
        LedgerJournalEntryLineContract   ledgerJournalEntryLineContract;
        ListEnumerator                      ledgerJourEntryLinesEnum;
        LedgerJournalTable                  ledgerJournalTable;
    
        if (StudentTrans::isBankChequeProcess(_journalEntryType, _paymentType))
        {
            ledgerJourEntryLinesEnum = _ledgerJourEntryLines.getEnumerator();
    
            while (ledgerJourEntryLinesEnum.moveNext())
            {
                ledgerJournalEntryLineContract = ledgerJourEntryLinesEnum.current();
    
                //if (ledgerJournalEntryLineContract.parmBankChequeNum())
                //{
                ledgerJournalTable = ledgerJournalTable.FindByStudentTransIdInSIS(ledgerJournalEntryLineContract.parmTransIdInSIS(),
                                                                                        ledgerJournalEntryLineContract.parmJournalEntryType());
                if (ledgerJournalTable)
                {
                    return  ledgerJournalTable;
                }
                //}
            }
        }
    
        return  ledgerJournalTable;
    }

    /// <summary>
    ///     Initializes the map of transaction types and transactions from
    ///     the <c>LedgerJournalEntryContract</c> contract class.
    /// </summary>
    /// <returns>
    ///     An instance of the map of transaction types and transactions.
    /// </returns>
    public Map getJournalEntryLinesMap()
    {
        List                              entryLineList;
        ListEnumerator                    ledgerJournalEntryLinesEnum;
        LedgerJournalEntryLineContract entryLineContract;
        container                         entryTypeKeyCon;
        int                               transGroupCounter;
        Map                               entryLinesMap = new Map(Types::Container, Types::Class);
    
        #define.TransGroupUniqueIdentifier("TransGroupUniqueIdentifier")
    
        ledgerJournalEntryLinesEnum     = ledgerJournalEntryContract.parmLedgerJourEntryLines().getEnumerator();
    
        while (ledgerJournalEntryLinesEnum.moveNext())
        {
            entryLineContract = ledgerJournalEntryLinesEnum.current();
    
            if (StudentTrans::isBankChequeProcess(entryLineContract.parmJournalEntryType(), entryLineContract.parmSISPaymentType())
             && entryLineContract.parmMasterChequeGroup())
            {
                entryTypeKeyCon = [entryLineContract.parmJournalEntryType(), entryLineContract.parmSISPaymentType(), entryLineContract.parmMasterChequeGroup()];
            }
            else
            {
                transGroupCounter++;
                entryTypeKeyCon = [entryLineContract.parmJournalEntryType(), entryLineContract.parmSISPaymentType(), strFmt("%1%2", #TransGroupUniqueIdentifier, transGroupCounter)];
            }
    
            if (!entryLinesMap.exists(entryTypeKeyCon))
            {
                entryLineList = new List(Types::Class);
                entryLineList.addEnd(entryLineContract);
    
                entryLinesMap.insert(entryTypeKeyCon, entryLineList);
            }
            else
            {
                entryLineList = entryLinesMap.lookup(entryTypeKeyCon);
                entryLineList.addEnd(entryLineContract);
    
                entryLinesMap.insert(entryTypeKeyCon, entryLineList);
            }
        }
    
        return entryLinesMap;
    }

    /// <summary>
    ///    Gets student transaction SIS Ids.
    /// </summary>
    /// <param name="_ledgerJourEntryLines">
    ///     List of <c>LedgerJournalEntryLineContract</c> contract classes.
    /// </param>
    /// <returns>
    ///     Container of student transaction SIS Ids.
    /// </returns>
    protected container getStudentTransIds(List _ledgerJourEntryLines)
    {
        LedgerJournalEntryLineContract   ledgerJournalEntryLineContract;
        container                           ret;
        ListEnumerator                      ledgerJournalEntryLinesEnum = _ledgerJourEntryLines.getEnumerator();
    
        while (ledgerJournalEntryLinesEnum.moveNext())
        {
            ledgerJournalEntryLineContract = ledgerJournalEntryLinesEnum.current();
    
            ret += ledgerJournalEntryLineContract.parmTransIdInSIS();
        }
    
        return  ret;
    }

    /// <summary>
    ///     Initializes <c>LedgerJournalEntryPostStatusContract</c> contract class.
    /// </summary>
    protected void initEntryPostStatusContract()
    {
        ledgerJournalEntryPostStatusContract = new LedgerJournalEntryPostStatusContract();
        ledgerJournalEntryPostStatusContract.parmPostedJournals(new List(Types::String));
        ledgerJournalEntryPostStatusContract.initializeMessages();
    }

    public static void markPostedTrans(Map _postedTransMap)
    {
        new SISIntegrationServiceAdapter().sendPostedStudentTrans(_postedTransMap);
    }

    public void new()
    {
        super();
    
        studentTransRecIdPostedSet = new Set(Types::Int64);
    }

    /// <summary>
    ///     Gets or sets the value of the <c>LedgerJournalEntryContract</c> class parameter.
    /// </summary>
    /// <param name="_ledgerJournalEntryContract">
    ///     The new value of the <c>LedgerJournalEntryContract</c> class parameter; optional.
    /// </param>
    /// <returns>
    ///     The current value of the <c>LedgerJournalEntryContract</c> class parameter.
    /// </returns>
    public LedgerJournalEntryContract parmLedgerJournalEntryContract(LedgerJournalEntryContract _ledgerJournalEntryContract = ledgerJournalEntryContract)
    {
        ledgerJournalEntryContract = _ledgerJournalEntryContract;
        return ledgerJournalEntryContract;
    }

    /// <summary>
    ///     Gets or sets the value of the <c>LedgerJournalEntryPostStatusContract</c> class parameter.
    /// </summary>
    /// <param name="_ledgerJournalEntryPostStatusContract">
    ///     The new value of the <c>LedgerJournalEntryPostStatusContract</c> class parameter; optional.
    /// </param>
    /// <returns>
    ///     The current value of the <c>LedgerJournalEntryPostStatusContract</c> class parameter.
    /// </returns>
    public LedgerJournalEntryPostStatusContract parmLedgerJournalEntryPostStatusContract(LedgerJournalEntryPostStatusContract _ledgerJournalEntryPostStatusContract = ledgerJournalEntryPostStatusContract)
    {
        ledgerJournalEntryPostStatusContract = _ledgerJournalEntryPostStatusContract;
        return  ledgerJournalEntryPostStatusContract;
    }

    /// <summary>
    ///     Gets or sets the value of the <c>studentTransRecIdPostedSet</c> parameter.
    /// </summary>
    /// <param name="_studentTransRecIdPostedSet">
    ///     The new value of the <c>studentTransRecIdPostedSet</c> parameter; optional.
    /// </param>
    /// <returns>
    ///     The current value of the <c>studentTransRecIdPostedSet</c> parameter.
    /// </returns>
    public Set parmStudentTransRecIdPostedSet(Set _studentTransRecIdPostedSet = studentTransRecIdPostedSet)
    {
        studentTransRecIdPostedSet = _studentTransRecIdPostedSet;
        return studentTransRecIdPostedSet;
    }

    /// <summary>
    ///     Posts the ledger journal.
    /// </summary>
    /// <param name="_ledgerJournalTable">
    ///     Ledger journal to post.
    /// </param>
    protected void postJournal(LedgerJournalTable   _ledgerJournalTable)
    {
        LedgerJournalCheckPost  ledgerJournalCheckPost;
        LedgerJournalTable      ledgerJournalTable;
    
        if (!_ledgerJournalTable)
        {
            throw error("@1401");
        }
    
        ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(_ledgerJournalTable, NoYes::Yes);
    
        if (this.canPostLedgerJournal(_ledgerJournalTable))
        {
            ledgerJournalCheckPost.parmSkipBlockedForManualEntryCheck(true);
            ledgerJournalCheckPost.runOperation();
        }
    
        ledgerJournalTable = ledgerJournalTable::find(_ledgerJournalTable.JournalNum);
    
        if (!ledgerJournalTable.Posted)
        {
            throw error("@1402");
        }
    }

    /// <summary>
    ///    Posts student transactions.
    /// </summary>
    /// <param name="_journalNum">
    ///     Ledger journal Id.
    /// </param>
    /// <param name="_ledgerJourEntryLines">
    ///     List of <c>LedgerJournalEntryLineContract</c> contract classes.
    /// </param>
    protected void postStudentTrans(LedgerJournalId   _journalNum,
                                    List              _ledgerJourEntryLines)
    {
        LedgerJournalEntryLineContract   ledgerJournalEntryLineContract;
        StudentTrans                     studentTrans;
        container                           mapKey;
        ListEnumerator                      ledgerJournalEntryLinesEnum = _ledgerJourEntryLines.getEnumerator();
        Map                                 transLedgerJournalIdMap     = new Map(Types::Container, Types::Class);
        Set                                 journalNumSet               = new Set(Types::String);
    
        journalNumSet.add(_journalNum);
    
        while (ledgerJournalEntryLinesEnum.moveNext())
        {
            ledgerJournalEntryLineContract = ledgerJournalEntryLinesEnum.current();
    
            mapKey = [ledgerJournalEntryLineContract.parmTransIdInSIS(), ledgerJournalEntryLineContract.parmJournalEntryType()];
    
            transLedgerJournalIdMap.insert(mapKey, journalNumSet);
    
            studentTrans        = StudentTrans::find(ledgerJournalEntryLineContract.parmTransIdInSIS(),
                                                        ledgerJournalEntryLineContract.parmJournalEntryType(),
                                                        true);
            studentTrans.Posted = true;
            if(studentTrans.SISPaymentType == SISPaymentType::Check)
                studentTrans.PendingChequeInSIS = false;
    
            if (!studentTrans.validateWrite())
            {
                throw error("@SYS18447");
            }
    
            studentTrans.updateSkipDatabaseLog(true);
    
            if (studentTrans.isValidForFundSourceTrans())
            {
                if (FundSourceTrans::findByStudentTrans(studentTrans.RecId))
                {
                    FundSourceTrans::updateExist(studentTrans);
                }
                else
                {
                    FundSourceTrans::create(studentTrans);
                }
            }
    
            if (StudentAccountingParameters::isCampusNexusMode())
            {
                LedgerJournalEntryPost::markPostedTrans(transLedgerJournalIdMap);
            }
    
            studentTransRecIdPostedSet.add(studentTrans.RecId);
        }
    }

    /// <summary>
    ///     Executes business logic of the class.
    /// </summary>
    public void run()
    {
        LedgerJournalTable      ledgerJournalTable;
        JournalEntryType     journalEntryType;
        SISPaymentType       paymentType;
        AifInfoLog              aifInfoLog;
        List                    ledgerJourEntryLines;
        Name                    groupName;
        boolean                 exceptionThrown;
        MapEnumerator           entryLinesMapEnum;
    
        this.initEntryPostStatusContract();
    
        entryLinesMapEnum = this.getJournalEntryLinesMap().getEnumerator();
    
        while (entryLinesMapEnum.moveNext())
        {
            [journalEntryType, paymentType, groupName]  = entryLinesMapEnum.currentKey();
            ledgerJourEntryLines                        = entryLinesMapEnum.currentValue();
            aifInfoLog                                  = new AifInfoLog();
    
            try
            {
                ttsBegin;
    
                this.validateLedgerJourEntryLines(ledgerJourEntryLines);
    
                ledgerJournalTable = this.findOrCreateJournal(ledgerJourEntryLines, journalEntryType, paymentType);
    
                this.postJournal(ledgerJournalTable);
                this.postStudentTrans(ledgerJournalTable.JournalNum, ledgerJourEntryLines);
    
                ttsCommit;
    
                if (ledgerJournalTable.Posted)
                {
                    ledgerJournalEntryPostStatusContract.parmPostedJournals().addEnd(ledgerJournalTable.JournalNum);
                }
            }
            catch (Exception::Error)
            {
                exceptionThrown = true;
                this.updateEntryPostStatus(aifInfoLog, LedgerJournalCreatePostStatus::Error, this.getStudentTransIds(ledgerJourEntryLines));
            }
            catch (Exception::CLRError)
            {
                exceptionThrown = true;
                error(AifUtil::getClrErrorMessage());
                this.updateEntryPostStatus(aifInfoLog, LedgerJournalCreatePostStatus::Error, this.getStudentTransIds(ledgerJourEntryLines));
            }
            catch
            {
                exceptionThrown = true;
                this.updateEntryPostStatus(aifInfoLog, LedgerJournalCreatePostStatus::Error, this.getStudentTransIds(ledgerJourEntryLines));
            }
        }
    
        if (!exceptionThrown && !ledgerJournalEntryPostStatusContract.parmPostedJournals().empty())
        {
            ledgerJournalEntryPostStatusContract.parmStatus(LedgerJournalCreatePostStatus::Posted);
        }
    }

    /// <summary>
    ///     Updates <c>LedgerJournalEntryPostStatusContract</c> contract class.
    /// </summary>
    /// <param name="_aifInfoLog">
    ///     An object of <c>AifInfoLog</c> class.
    /// </param>
    /// <param name="_postStatus">
    ///     Operation status.
    /// </param>
    /// <param name="_studentTransIdCon">
    ///     Container of student transaction SIS Ids.
    /// </param>
    protected void updateEntryPostStatus(AifInfoLog                         _aifInfoLog,
                                         LedgerJournalCreatePostStatus   _postStatus,
                                         container                          _studentTransIdCon)
    {
        SysInfologEnumerator infologEnum;
    
        if (!ledgerJournalEntryPostStatusContract)
        {
            this.initEntryPostStatusContract();
        }
    
        ledgerJournalEntryPostStatusContract.parmStatus(_postStatus);
    
        AifFault::fault(strFmt("@1403", "@141", con2str(_studentTransIdCon, ', ')), #LedgerJournalTableCreationFailed);
    
        infologEnum = SysInfologEnumerator::newData(_aifInfoLog.getInfoLogData());
    
        while (infologEnum.moveNext())
        {
            ledgerJournalEntryPostStatusContract.addMessage(IntegrationServiceProvider::trimLeadingTabs(infologEnum.currentMessage()));
        }
    }

    /// <summary>
    ///     Validates ledger journal entry lines.
    /// </summary>
    /// <param name="_ledgerJourEntryLines">
    ///     List of <c>LedgerJournalEntryLineContract</c> contract classes.
    /// </param>
    protected void validateLedgerJourEntryLines(List    _ledgerJourEntryLines)
    {
        LedgerJournalEntryLineContract ledgerJournalEntryLineContract;
        StudentTrans                   studentTrans;
        ListEnumerator                    ledgerJournalEntryLinesEnum = _ledgerJourEntryLines.getEnumerator();
    
        while (ledgerJournalEntryLinesEnum.moveNext())
        {
            ledgerJournalEntryLineContract = ledgerJournalEntryLinesEnum.current();
            studentTrans                    = StudentTrans::find(ledgerJournalEntryLineContract.parmTransIdInSIS(), ledgerJournalEntryLineContract.parmJournalEntryType());
    
            if (studentTrans.Posted)
            {
                throw error(strfmt("@1399", studentTrans.description()));
            }
    
            if (StudentTrans::isBankChequeProcess(studentTrans.JournalEntryType, studentTrans.SISPaymentType)
             && !studentTrans.BankChequeNum)
            {
                throw error(strFmt("@1400", studentTrans.description()));
            }
        }
    }

    /// <summary>
    ///     Creates a new instance of the <c>LedgerJournalEntryPost</c> class.
    /// </summary>
    /// <param name="_ledgerJournalEntryContract">
    ///     Value of the <c>LedgerJournalEntryContract</c> contract class.
    /// </param>
    /// <returns>
    ///    Created instance of the <c>LedgerJournalEntryPost</c> class.
    /// </returns>
    public static server LedgerJournalEntryPost construct(LedgerJournalEntryContract _ledgerJournalEntryContract)
    {
        LedgerJournalEntryPost   ledgerJournalEntryPost = new LedgerJournalEntryPost();
    
        ledgerJournalEntryPost.parmLedgerJournalEntryContract(_ledgerJournalEntryContract);
    
        return  ledgerJournalEntryPost;
    }

    /// <summary>
    ///     Creates an object of <c>LedgerJournalEntryContract</c> contract class.
    /// </summary>
    /// <param name="_studentTransRecIdPacked">
    ///     Packed set of <c>StudentTrans</c> record Ids.
    /// </param>
    /// <returns>
    ///     An object of <c>LedgerJournalEntryContract</c> contract class.
    /// </returns>
    public static server LedgerJournalEntryContract createJournalEntryContractList(container   _studentTransRecIdPacked)
    {
        StudentTrans                 studentTrans;
        StudentTrans                 studentTransMasterCheque;
        LedgerJournalEntryContract   ledgerJournalEntryContract  = new LedgerJournalEntryContract();
        Set                             masterChequeGroup           = new Set(Types::String);
        Set                             studentTransRecIdSet        = Set::create(_studentTransRecIdPacked);
        SetEnumerator                   se                          = studentTransRecIdSet.getEnumerator();
    
        ledgerJournalEntryContract.parmLedgerJourEntryLines(new List(Types::Class));
    
        while (se.moveNext())
        {
            studentTrans = StudentTrans::findRecId(se.current());
    
            if (studentTrans.MasterChequeGroup && !masterChequeGroup.in(studentTrans.MasterChequeGroup))
            {
                masterChequeGroup.add(studentTrans.MasterChequeGroup);
    
                while select studentTransMasterCheque
                    where studentTransMasterCheque.MasterChequeGroup == studentTrans.MasterChequeGroup
                {
                    ledgerJournalEntryContract.parmLedgerJourEntryLines().addEnd(studentTransMasterCheque.ledgerJournalEntryLineContract());
                }
            }
            else if (!studentTrans.MasterChequeGroup)
            {
                ledgerJournalEntryContract.parmLedgerJourEntryLines().addEnd(studentTrans.ledgerJournalEntryLineContract());
            }
        }
    
        return  ledgerJournalEntryContract;
    }

    /// <summary>
    ///     Performs transaction posting from user interface.
    /// </summary>
    /// <param name="_args">
    ///     Parameters object.
    /// </param>
    public static void main(Args _args)
    {
        LedgerJournalEntryPost   ledgerJournalEntryPost;
        StudentTrans             studentTrans;
        FormDataSource              ds;
        Set                         studentTransRecIdSet = new Set(Types::Int64);
    
        if (!_args || !_args.dataset())
        {
            throw Error(Error::wrongUseOfFunction(funcName()));
        }
    
        if (FormDataUtil::isFormDataSource(_args.record()))
        {
            ds              = FormDataUtil::getFormDataSource(_args.record());
            studentTrans    = ds.getFirst(true) ? ds.getFirst(true) : ds.cursor();
    
            while (studentTrans)
            {
                studentTransRecIdSet.add(studentTrans.RecId);
                studentTrans = ds.getNext();
            }
        }
        else
        {
            studentTrans = _args.record();
            studentTransRecIdSet.add(studentTrans.RecId);
        }
    
        ledgerJournalEntryPost = LedgerJournalEntryPost::newFromLedgerJournalEntryContract(LedgerJournalEntryPost::createJournalEntryContractList(studentTransRecIdSet.pack()));
        ledgerJournalEntryPost.runOperation();
    
        info(strFmt("@561", ledgerJournalEntryPost.parmStudentTransRecIdPostedSet().elements()));
    
        if (ds)
        {
            ds.research(true);
        }
    }

    /// <summary>
    ///     Creates a new instance of the <c>LedgerJournalEntryPost</c> class and initilizes its parameters.
    /// </summary>
    /// <param name="_ledgerJournalEntryContract">
    ///     Value of the <c>LedgerJournalEntryContract</c> contract class.
    /// </param>
    /// <returns>
    ///    Created instance of the <c>LedgerJournalEntryPost</c> class.
    /// </returns>
    public static server LedgerJournalEntryPost newFromLedgerJournalEntryContract(LedgerJournalEntryContract _ledgerJournalEntryContract)
    {
        LedgerJournalEntryPost ledgerJournalEntryPost = new LedgerJournalEntryPost();
    
        LedgerJournalEntryPost::validateLedgerJournalEntryContract(_ledgerJournalEntryContract);
    
        ledgerJournalEntryPost.parmLedgerJournalEntryContract(_ledgerJournalEntryContract);
    
        return ledgerJournalEntryPost;
    }

    /// <summary>
    ///     Validates the <c>LedgerJournalEntryContract</c> contract class.
    /// </summary>
    /// <param name="_ledgerJournalEntryContract">
    ///     An instance of the <c>LedgerJournalEntryContract</c> contract class.
    /// </param>
    public static void validateLedgerJournalEntryContract(LedgerJournalEntryContract _ledgerJournalEntryContract)
    {
        if (!_ledgerJournalEntryContract)
        {
            throw error(strFmt("@35", classStr(LedgerJournalEntryContract)));
        }
    
        if (!_ledgerJournalEntryContract.parmLedgerJourEntryLines()
         || _ledgerJournalEntryContract.parmLedgerJourEntryLines().empty())
        {
            throw error("@36");
        }
    }

    protected boolean canRunInNewSession()
    {
        return false;
    }

}

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8