web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Need to update stored (packed/serialized) parameter for recurring batch job via x++

(2) ShareShare
ReportReport
Posted on by 98
Greetings,
 
I've created a custom batch job using the SysOperations framework with the required Controller, Contract, and Service classes. Is there an existing method on any of these classes that I can use to update a stored parameter for a recurring batch job?
 
My scenario's context:
 
Recurring batch job cleans transactional tables that could take some time to accomplish. I've set a runtime limit to not allow it to run during business hours, but I want the next job run to persist with the next record in the table. So I have a hidden parameter on the batch job that will be used to store the last processed RecId. But I need a way to update this RecId parameter on the batch job record.
 
Looking through some of the base class code and the Batch table, I can see that at some point the Contract parameters are stored in a container, serialized, and placed in the parameters field on the batch table record. My hope is that Microsoft has provided a method to cleanly update these parameters.... or I might have to try to figure out a way to deserialize this data, update it, and then put it back at the end of my job.
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    Is this about F&O or Dynamics AX? You've selected both Dynamics 365 Finance and Microsoft Dynamics AX categories for this thread.
     
    What you ask for can technically be done, but it sounds like a more complicated design than necessary and it goes againts how parametes are normally used for recurring batches. (You set batch parameters and a recurrence and instances of the batch use the same parameters.)
     
    The usual design is storing an information on a record to indicicate its state. For example, transactions could have a flag indicating that they're ready for deletion and your batch will process a certain number of these records (and continue on the next run). Or maybe you can build the conditions without a status field, e.g. saying that all transactions older than a parameter value are to be deleted.
    You can even have multiple threads doing the work in parallel (with careful design avoiding a lock escalation, for instance).
     
    If you want to stick to your design of storing the next RecId, you can use a dedicated table for that. You'll simply write to a field without all the problems with serialization etc.
  • jmcmillan Profile Picture
    98 on at
     
    I chose both F&O and AX as I figured a SysOperations framework would be beneficial for either environment. We are an F&O customer though to be more precise and give more context.
     
    The cleanup job I'm working on is for preexisting transactional tables that I do not want to create a field for a flag or introduce additional logic to set it. Interestingly, our use-case for this is a little unique as our company is creating a sales confirmation record for every open sales order every 10 minutes. Downstream integrations are needing this to occur. So as you can imagine, the CustConfirmJour and related tables have grown quite large.
     
    The cleanup job I'm creating can be used in different ways to help maintain these tables. One could be a recurring job set to traverse then entire table evaluating records from the beginning. This will take several hours/days to complete, so the need for it to persists in subsequent runs exists. I didn't want to create a table just to store a single piece of data if there was a way to already store it within the batch job record itself. I think there are other use-cases for this type of functionality, so perhaps I'll submit it as an idea.
     
    But again, if there are several maintenance jobs of this nature that run like this, it would be handy if this functionality existed instead of relying on a new table to store this information.
     
     
  • Verified answer
    jmcmillan Profile Picture
    98 on at
    I was able to figure it out!
     
    Took me a minute... but, all I did was add this overridden SysOperationServiceController method in my Controller class.
     
    protected void afterOperation(SysOperationExecutionMode _executionMode, AifAsyncResult _asyncResult)
    {
        // Serialize parameters with any updates to data contract from service class
        container packedUpdatedParms = this.pack();
    
        ttsbegin;
        currentBatch.Parameters = packedUpdatedParms;
        currentBatch.update();
        ttscommit;
    
        super(_executionMode, _asyncResult);
    }
     
    So now, I can modify any data contract parameter from within my Service class like the below example. Then whenever the above code is run at the end of the operation, it will reserialize the parameters in their current state and update the field on the Batch table.
     
    class RRLSalesConfirmationCleanupService extends SysOperationServiceBase
    {
        /// <summary>
        /// Main process method used to run the batch service.
        /// </summary>
        /// <param name = "_contract">Parameters passed by a contract class</param>
        public void process(RRLSalesConfirmationCleanupContract _contract)
        {
            RecId lastRecId = _contract.parmLastRecId();
            
            info(strFmt("LastRecId: %1", int2Str(lastRecId)));
            lastRecId++;
    
            _contract.parmLastRecId(lastRecId);        
        }
    }
     
    No need for a separate table to hold persistent data between job runs.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans