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

Notifications

Announcements

No record found.

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
    237,801 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
    237,801 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans