Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Incorrect session date...
Finance forum
Suggested answer

Incorrect session date when posting inventory journal

Posted on by 12
Hi experts,
 
I am facing a strange issue when posting inventory journal with session date.
 
Here is the step:
1. Today is 11/2/2024, and session date is changed to 10/31/2024.
2. Controller class is running with dialog and CanRunInNewSession = TRUE.
3. An inventory journal is created via x++ code, and the transaction date of lines are assigned with function DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()).
4. The transaction date of lines are created as Today instead of session date 10/31/2024.
 
I guess that the session date is lost when new session running, perhaps the value must be packed into current list?
However, I have looked into some standard code with CanRunInNewSession = true, pack and unpack methos are not implemented in most of them.
Can anyone give me some advice?
 
Thanks in advance.
 
Bernard
Categories:
  • Suggested answer
    Saif Ali Sabri Profile Picture
    Saif Ali Sabri 46 on at
    Incorrect session date when posting inventory journal

    When the new session is created, it typically relies on the system date rather than inheriting the session date you set previously.

    To ensure that the intended session date (10/31/2024) is applied, you could explicitly pass this date through a pack method in your controller class. While it's true that not all standard implementations use pack and unpack, adding these methods will allow you to transfer custom values, such as the session date, into the new session.

    Here’s a basic approach:

    1. Implement pack and unpack methods in your controller class to store the session date.
    2. In the pack method, add the session date to a container that can be accessed in the new session.
    3. Use the unpack method to retrieve the session date and apply it where needed.

    For example:

    public container pack()
    {
    return [#CurrentVersion, this.sessionDate];
    }
    
    public boolean unpack(container _packedClass)
    {
    Version version = RunBase::getVersion(_packedClass);
    switch (version)
    {
    case #CurrentVersion:
    [version, this.sessionDate] = _packedClass;
    break;
    default:
    return false;
    }
    return true;
    }

    Then, set this.sessionDate to the session date when you instantiate the controller. This way, when you use DateTimeUtil::getSystemDate() in the new session, you can substitute it with this.sessionDate where needed.

  • YQ-12070237-0 Profile Picture
    YQ-12070237-0 12 on at
    Incorrect session date when posting inventory journal
    I find the sulotion like this
    1. Add parmTransDate method to contract class.
    2. Call parmTransDate and pass session date in main method of controller class.
    3. Assign transaction date of inventory journal lines with parmTransDate.
     
    Does anyone have other suggestions?

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

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,802 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,129 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,154

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans