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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

LineAmount, Price and itemName are not being set when creating sales order by code

(1) ShareShare
ReportReport
Posted on by 252
Hi,

If I do the following, LineAmount, Name and price gets reseted to 0 after I use the createLine
 
       salesLine.initFromSalesTable(_salesTable);
 
       salesLine.ItemId             = _salesOrderLineContract.ItemId();
        if(_salesOrderLineContract.ItemName())
        {
            salesLineName = _salesOrderLineContract.ItemName();
        }
       salesLine.SalesPrice       = _salesOrderLineContract.SalesPrice();
       salesLine.SalesQty         = _salesOrderLineContract.SalesQty();
        salesLine.LineAmount  = salesLine.calcLineAmount();
        salesLine.createLine(true, false, true, true, true, true);

So I update the salesLine back again:
select firstonly forupdate salesLineLocal where salesLineLocal.SalesId == _salesLine.SalesId
            && salesLineLocal.LineNum == _salesLine.LineNum;
        if(_salesOrderLineContract.ItemName())
        {
            salesLineLocal.Name = _salesOrderLineContract.ItemName();
        }
        salesLineLocal.SalesPrice               = _salesOrderLineContract.SalesPrice();
        salesLineLocal.LineAmount           = salesLineLocal.calcLineAmount();
        salesLineLocal.update();

is there another way? I think it's happening because of the the third parameter in createLine _initFromItemOrCategory

Does this mean I need to call salesLine.initLineFromItemOrCategory() before setting prices? then set the parameter as false in the createLine? but would i miss anything from standard behaviour if i do this?


I mean like this:
salesLine.initFromSalesTable(_salesTable);
salesLine.ItemId    = _salesOrderLineContract.ItemId();
salesLine.initLineFromItemOrCategory();
if(_salesOrderLineContract.ItemName())
{
     salesLineName = _salesOrderLineContract.ItemName();
 }
salesLine.SalesPrice       = _salesOrderLineContract.SalesPrice();
salesLine.SalesQty         = _salesOrderLineContract.SalesQty();
salesLine.LineAmount  = salesLine.calcLineAmount();
salesLine.createLine(true, false, false, true, true, true);


Question not related: Do i need to call SalesLine.ItemIdChanged() as well when creating sales order by code? if yes why?

 
  • Suggested answer
    Waed Ayyad Profile Picture
    9,222 Super User 2026 Season 2 on at
    Hi,
     
    I think the better way to know where the issue is to debug the code, put break point and start debugging you can watch the buffer fields while you debugging the code.
     
    But I see from your code you set the salesline fields then you use another buffer, why you use two buffers?
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     
     
     
     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 511 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 426 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 159

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans