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)

Insert Sales Order Lines by Code

(0) ShareShare
ReportReport
Posted on by 209

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

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    238,743 Most Valuable Professional on at

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

    initValue() and validateWrite() are other examples.

  • XSpy Profile Picture
    209 on at

    thanks for the reply Martin,

    so where should i put the itemchanged() code?

  • XSpy Profile Picture
    209 on at

    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?

  • Verified answer
    Martin Dráb Profile Picture
    238,743 Most Valuable Professional on at

    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.

  • Verified answer
    5400 Profile Picture
    7,162 on at

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

    and call salesline.itemIdChanged() - unit and quantity

  • XSpy Profile Picture
    209 on at

    Thanks Martin and Bhaskar Roy, got it working now.

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
Sagar Suman Profile Picture

Sagar Suman 2 Super User 2026 Season 1

#1
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#1
Pratik Bhosle Profile Picture

Pratik Bhosle 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans