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

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...