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 :
Microsoft Dynamics AX (Archived)

automatically assign a value to a field with an X++ function in every new registration

(0) ShareShare
ReportReport
Posted on by

Hi,

I want to automatically assign the week of the year number to the InventBatchId field when i register a new order from the account receivable screen.

The field usually gets it's value from a list of values added by the user and registred in the InventBatch table.

I know that i can use the wkOfYr function but i don't know how to write the method and where to put it exactly so that the field starts getting it's value from the function and not from the InventDim table.

Can someone help me here? It must be a simple manipulation but it's the first time i'm doing something like this. Thank you

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi Ameni,

    You need to make modifications to the method initValue associated with the form.

    Below I modified initValue for form PurchTable and added the 3 lines tagged with your name. I used int2str to convert the integer to a string as the destination field ProjId is a string:

    void initValue()

    {

       date dateTest;                                                     //ameni

       super();

       purchTableForm.initValues();

       purchTable.PurchaseType = purchTableForm.defaultPurchaseType();

       purchTable.ProjId       = purchTableForm.projId();

       dateTest = 16\10\2003;                                      //ameni

       PurchTable.ProjId = int2str(wkOfYr(dateTest));  //ameni

       element.changeType(purchTable.PurchaseType);

    }

    This is the location of the method:

    6675.Capture.JPG

  • Verified answer
    jasman Profile Picture
    1,413 on at

    Hello,

    As I understand you challenge it is to initialize the batch number field of a SO line.

    I think that your problem can be divided into two subproblems.

    1) If you use the batch number field to store the week number, the week number must be present in the InventBatch table for the item in question.

    2) You can't avoid that the batch no field is initialized from InventDim, as it is in fact a field ON InventDim.

    Therefor to initialize the batch number field on a SO line with a given week number, your strategy should be:

    1) Create the necessary record in the InventBatch table (ItemId and weeknumber in InventBatchID)

    2) Do a call to InventDim::FindOrCreate() to create a InventDim record that contains the right combination of Invent dimensions (in this case just the week number).

    3) Assing the InventDimId of your newly created InventDim record to the SO Line

  • Community Member Profile Picture
    on at

    Thank you AXatak, I already found another solution but i'm learning here ^^

  • Community Member Profile Picture
    on at

    Hi Jacob,

    I worked with a method similar to yours, thank you for the answer

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans