Friday, February 17, 2023

Delete Recurring Batch Job in D365FO X++

 public static void deleteRecurringBatchJob(ClassName _className, str _errorMessage)

    {

        Batch batch;

        BatchHistory batchHistory;

        BatchJob batchJob;

        BatchJobHistory batchJobHistory;


        select firstonly forupdate  from batchJob

            join forupdate from batch

                where batchJob.RecId == batch.BatchJobId

                    && batch.ClassNumber == className2Id(_className);


        if (batch.statusClass().canDelete()

            && batchJob.Status != BatchStatus::Executing

            && batchJob.Status != BatchStatus::Scheduled

            && batchJob.Status != BatchStatus::Cancelling)

        {

            ttsbegin;

            delete_from batchHistory

                where batchHistory.BatchJobId == batchJob.RecId;


            delete_from batchJobHistory

                where batchJobHistory.BatchJobId == batchJob.RecId;


            batch.delete();

            batchJob.delete();

            ttscommit;

        }

        else

        {

            throw error(_errorMessage);

        }

    }


No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...