Create a run base batch job to post inventory counting journal.

 Today we have a requirement to create a runbase batch which will post the invent counting journal in batch..


class AVAAutomaticInventCountingJournalPosting extends RunBaseBatch

{

    InventJournalNameId journalName;

    dialogfield         journalNameField;

    

    #DEFINE.CurrentVersion(1)

    #LOCALMACRO.CurrentList

        journalName

    #ENDMACRO

    


    public container pack()

    {

        return [#CurrentVersion, #CurrentList];

    }


    public LedgerJournalNameId parmJournalName(InventJournalNameId  _journalName = journalName)

    {

        journalName = _journalName;

 

        return journalName;

    }


    public Object dialog()

    {

        DialogRunbase dialog = super();

 

        journalNameField = dialog.addField(extendedTypeStr(InventJournalNameId));

        journalName = InventJournalName::find(InventParameters::find().CountJournalNameId).JournalNameId;

        journalNameField.value(journalName);

         

        return dialog;

    }


    public boolean getFromDialog()

    {

        boolean         ret;

 

        ret = super();

        journalName  = journalNameField.value();

 

        return ret;

    }


    /// <summary>

    /// Contains the code that does the actual job of the class.

    /// </summary>

    public void run()

    {

        InventJournalTable  inventJournalTable;

        JournalCheckPost    inventJournalCheckPost;

 

        try

        {

            while select forupdate inventJournalTable

                where inventJournalTable.JournalNameId == this.parmJournalName()

                   && inventJournalTable.AVAAutoPost == NoYes::Yes

                && inventJournalTable.Posted == NoYes::No

            {

                ttsbegin;

                inventJournalTable.AVAAutoPost = NoYes::No;

                inventJournalTable.doUpdate();

                ttscommit;


                JournalCheckPost journalCheckPost = InventJournalCheckPost::newJournalCheckPost(JournalCheckPostType::Post, inventJournalTable);

                

                journalCheckPost.parmJournalTableId(tableNum(InventJournalTable));

                journalCheckPost.parmJournalId(inventJournalTable.JournalId);

                journalCheckPost.parmInBatch(true);

                journalCheckPost.parmThrowCheckFailed(false);

                journalCheckPost.parmTransferErrors(true);

                journalCheckPost.runOperation();

            }

        }


        catch

        {

                

        }

    }


    /// <summary>

    /// Determines whether the batch task is run on the server or on a client.

    /// </summary>

    /// <returns>

    /// true if the task is run on the server; otherwise, false.

    /// </returns>

    /// <remarks>

    /// Your classes that extend <c>RunBaseBatch</c> must override the <c>runsImpersonated</c> method and

    /// return false, if you want those tasks to run on a client.

    /// </remarks>

    public boolean runsImpersonated()

    {

        return true;

    }


    /// <summary>

    /// Determines whether to add a Select button to the dialog box.

    /// </summary>

    /// <returns>

    /// Always returns true.

    /// </returns>

    /// <remarks>

    /// If you click this button, it will show the query form. Therefore, the <c>queryRun</c> method has to

    /// return a valid <c>queryRun</c> value.

    /// </remarks>

    public boolean showQueryValues()

    {

        return true;

    }


    public boolean unpack(container _packedClass)

    {

        Version     version = RunBase::getVersion(_packedClass);

        container   packedQuery;

 

        switch (version)

        {

            case #CurrentVersion :

                [version, #CurrentList, packedQuery] = _packedClass;

                break;

 

            default:

                return false;

        }

        return true;

    }


    public static AVAAutomaticInventCountingJournalPosting  construct()

    {

        return new AVAAutomaticInventCountingJournalPosting();

    }


    Static public ClassDescription description()

    {

        return "@AVAExtension:countingJournalAutoPostBatch";

    }


    client static void main(Args  args)

    {

        AVAAutomaticInventCountingJournalPosting     obj = AVAAutomaticInventCountingJournalPosting::construct();

        obj.parmInBatch(true);


        if (obj.prompt())

        {

            obj.runOperation();

        }

    }


    protected boolean canRunInNewSession()

    {

        return false;

    }


}

=======================================================

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++