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)

Run Replace by Alternate Item in Code (Sales Order Lines)

(0) ShareShare
ReportReport
Posted on by 209

In the Sales Order Lines, if the Item you add does not have stock, the Replace by Alternate Item will be prompted (when you save it)

it looks like this:

alrt.png

I have this code which adds Item Number / Sales Order Lines by button click,

now i need to run the Replace by Alternate Item in my code.

can you help me achieve it?

here's my code:

void clicked()
{
SalesLine.clear();
SalesLine.SalesId = SalesTable.SalesId;
SalesLine.ItemId = '0000000003';
SalesLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
salesline.initFromSalesTable(salestable);
SalesLine.itemIdChanged();
SalesLine.validateWrite();

SalesLine.createLine();

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

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

PS. im using the code to make a import from excel button, i just need to run the Replace by Alternate Item for now.

please help me, thanks.

*This post is locked for comments

I have the same question (0)
  • 5400 Profile Picture
    7,162 on at

    I will suggest you please add the logic before save the records in DB. once you are getting the inventory dimension value as per your code please check the inventory on-hand as per your present itemid and inventdim, if inventory on-hand is not there please display one dialog as you said above with ItemID lookup. If you want to change the itemid please select from lookup and save the records again with same validation.

  • XSpy Profile Picture
    209 on at

    isn't there any method that runs the lookup for the alternate item?

    because if it is working in manual, i think it has method.

    i need to get that to apply in my code.

  • 5400 Profile Picture
    7,162 on at

    For this, I don't think so you need customization. you have to set the parameters and system should check automatically above condition but you are calling same API in our code or not you have to check only.

    community.dynamics.com/.../117332

    community.dynamics.com/.../73251

  • XSpy Profile Picture
    209 on at

    is there any other way?

    i'm having a hard time composing the code because the on-hand inventory (the qty) can only be seen after saving the sales order line.

    is there a way to find what function did the AX use to Alternate Item Number in manual inserting of data?

  • Verified answer
    Florian Hopfner Profile Picture
    2,461 on at

    Take a look at class SalesAlternativeItem, depending on what you want to do, it could be as simple as

    SalesLine            salesLine;
    SalesAlternativeItem salesAlternativeItem;
    
    salesLine = SalesLine::find(mySalesId, myLineNum);
    salesAlternativeItem = SalesAlternativeItem::newAlternativeItem(salesLine);
    salesLine.setAlternativeItem(salesAlternativeItem);
    

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Sukrut Parab Profile Picture

Sukrut Parab 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans