Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Insert Sales Order Lines by Code

(0) ShareShare
ReportReport
Posted on by 207

Hello all, i need help here for inserting sales lines.

in manual inserting, if you Select a Item number, the Other Fields will automatically be filled with corresponding data, (Unit, Delivery Address, etc.)

see picture here(manual inserting)

X.png

--------------------------------

now, here's my problem, I have a Button that inserts a Item number / Sales Order Line, but it does not automatically fill the corresponding data fields (Unit, Delivery Address, etc.)

heres the picture after i click the Button:

5432.z.png

The Code i Used in the Button to Insert the Item number / Sales Order Line is :

----------

void clicked()
{
SalesLine.clear();
SalesLine.SalesId = SalesTable.SalesId;
SalesLine.ItemId = '0000000002';
SalesLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;

SalesLine.insert();

SalesLine_ds.refresh();
SalesLine_ds.executeQuery();
}

---------

Now, what i need is when I click the Button to Insert the Item Number/Sales Order Line, i want the same output as the Manual Inserting, i need to get the Unit, Delivery Address, etc. all other fields that is automatically filled when used Manual Insert.

can you help me achieve this in my Code?

Im using this coded version because i will use this to make a Importing Button Tool, but for now, i need this first step, which is to make the Other Fields automatic.

help me please, thanks

*This post is locked for comments

  • XSpy Profile Picture
    XSpy 207 on at
    RE: Insert Sales Order Lines by Code

    Thanks Martin and Bhaskar Roy, got it working now.

  • Verified answer
    5400 Profile Picture
    5400 7,162 on at
    RE: Insert Sales Order Lines by Code

    Please call after inventdim setting salesline.initFromSalesTable(salestable) - delivery address

    and call salesline.itemIdChanged() - unit and quantity

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,354 Most Valuable Professional on at
    RE: Insert Sales Order Lines by Code

    Rather than calling insert() directly, call createLine(). Look at how standard AX does it.

    By the validateWrite() and ignoring its return value isn't very useful. You would insert a new record if the validation said that it's invalid.

  • XSpy Profile Picture
    XSpy 207 on at
    RE: Insert Sales Order Lines by Code

    i changed it to :

    void clicked()

    {

       SalesLine.clear();

       SalesLine.SalesId = SalesTable.SalesId;

       SalesLine.ItemId = '0000000002';

       SalesLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;

       SalesLine.itemIdChanged();

       SalesLine.initValue();

       SalesLine.validateWrite();

       SalesLine.insert();

       SalesLine_ds.refresh();

       SalesLine_ds.executeQuery();

    }

    the Unit Field is automatically filled, but the Delivery Address and the other fields are still blank.

    what should i do?

  • XSpy Profile Picture
    XSpy 207 on at
    RE: Insert Sales Order Lines by Code

    thanks for the reply Martin,

    so where should i put the itemchanged() code?

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,354 Most Valuable Professional on at
    RE: Insert Sales Order Lines by Code

    You forgot to call a few methods, most importantly itemIdChanged().

    initValue() and validateWrite() are other examples.

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans