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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Incorrect session date when posting inventory journal

(1) ShareShare
ReportReport
Posted on by 57
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:
  • YQ-12070237-0 Profile Picture
    57 on at
    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?
  • Suggested answer
    Saif Ali Sabri Profile Picture
    2,864 Super User 2026 Season 2 on at

    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.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 539 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 431 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 184

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans