Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Set session date in a batch job

Posted on by Microsoft Employee

I have a batch job that process batch/production orders with data from a staging table.  I need to use a date field value, from each record in this table, to have the batch job session date change to whatever the date value is for each record - just as a user can change the session date and post the RAF journal - I basically need the batch job to do the same.  I tried some code to change the session date in code I found online but the batch job errors...any ideas?

*This post is locked for comments

  • Suggested answer
    Iain Wright Profile Picture
    Iain Wright 5 on at
    RE: Set session date in a batch job

    I had exactly the same issue. Sadly, the batch framework does not seem to allow you to change the session date during a batch job. To ensure all transactions relating to the productions are backdated, I think I will have to keep the process as a client user process or change all the code in every journal and req trans generation to accept a date parameter.

    If you were able to change the date of the batch session then please let me now how you did it 

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Set session date in a batch job

    Would you mind sharing the error message? Usually they are helpful when troubleshooting.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Set session date in a batch job

    when you process a production order, the inventory transaction dates follow the date of the session, so if a production order was actually processed on Jan 25, the table I setup for the queue of production records to process would have jan 25 as the date on a specific production order.  The batch job would read that record, change the date to jan 25 and process that production order, so all the posting dates show jan 25.  Then, the next record in the queue, let's say it has a date of jan 20.  The batch job reads that date and changes the session date to jan 20 and process that production order so all the posting dates show jan 20.  If I run the class (that gets run by the batch job) directly, it works perfectly.  The batch job errors and the only thing in the class I added was the line of code to change the date.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Set session date in a batch job

    What do you mean by "doesn't get past"? Do you get some error?

    Are you sure you can't tell the production order posting that the order was finished on date x, instead of current date? I still don't fully understand what you are trying to achieve.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Set session date in a batch job

    Our business always does the actual processing in AX after the event has occurred, so we always back-date postings to the date on the processing documents we receive from our processors.  So the production is physically done on various dates.  The processor gives us the info on the production, including the date it was processed and we back-date our session date when we post it in AX.  These processor documents go into a queue (table) and the batch job needs to change the session date to what is on the table record for each production order in order to post it on the correct date.  I have a batch job setup to process them and I utilize DateTimeUtil::setSystemDateTime() and pass in the date from the table record being processed in utc format.  It works perfectly if I execute the class manually, but when scheduled as a batch job, it doesn't get past the DateTimeUtil… code.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Set session date in a batch job

    The session date is what it is: the real date / time when the job runs. Are you sure that's what you want to change? What is the expected outcome of this?

    Do you want that some field in some table is not initialized as "current date / time" but instead some other date / time? I don't think that changing the session date / time is necessarily the correct way to achieve that.

    Also what would be the impact in batch job triggers, and atch job history, if you started manipulating the session date / time?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Set session date in a batch job

    That would just return the current date/time, no?  Basically what I am doing is processing production orders.  All the data to process them is added to a table by another process.  One of the fields in this table is the date that production order needs to be processed/posted on.  So as the batch job works its way through each production order, it should change the session date based on the date in the table, then process the production order.  It is possible that each production order would have a different date to be processed/posted on.

  • Suggested answer
    udaY-ch Profile Picture
    udaY-ch 4,624 on at
    RE: Set session date in a batch job

    Hi,

    Have you tried using DateTimeUtil::utcNow(). Also find the thread below which is similar to your question.

    community.dynamics.com/.../203815

    /Uday.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans