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

Change sales line's item number

(3) ShareShare
ReportReport
Posted on by 128
Hi,
 
I want to change the sales line's item number using a function.
Let's assume that all the other criteria are met such as inventory dim combination and so on.
 
Below is the code piece and it throws an error.
 
"Item identification cannot be changed when inventory transactions have been generated."
 
salesLine = SalesLine::findRecId(_salesLineRecId, true);
salesLine.ItemId = itemId;
salesLine.itemIdChanged();
salesLine.Update();   
 
Can anyone help me on this?
 
Cheers,
Gihan
Categories:
I have the same question (0)
  • Verified answer
    Jonas "Jones" Melgaard Profile Picture
    4,899 Most Valuable Professional on at
    It's not possible on Sales Orders in Dynamics F&O.
    When you enter an order line, Dynamics will create a lot for that particular order line. And while you haven't made any postings yet, it still creates expected issues and receipts.
     
    Process-wise, the only thing you can do is to either delete the line if you haven't made any postings against it, or cancel the line if you have, and then create a new line.
  • Verified answer
    Ramesh Kumar Profile Picture
    7,527 Super User 2025 Season 2 on at
    You cannot change ItemId on a SalesLine with existing inventory transactions. est and safest route: delete and recreate the SalesLine.
     
    Thanks
    Ramesh
     
    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.
     
     
  • egsameera Profile Picture
    128 on at
    Hi,
     
    Thanks for the responses. 
    I tried inserting the lines, but I couldn't set the sales price from the previous line. 
    Is there any amendments should I do to the below code?
     
    salesLineCur = SalesLine::findRecId(_salesLineRecId);
     
    buf2Buf(salesLineCur, salesLineIns);
    salesLineIns.ItemId                 =   itemId;
    salesLineIns.RetailVariantId    =   this.getRetailVariantId(salesLineCur);
    salesLineIns.InventTransId      =   '';
    salesLineIns.setPriceDiscChangePolicy(PriceDiscSystemSource::ManualEntry, fieldNum(SalesLine, SalesPrice));
    salesLineIns.createLine(true, true, true, true, true, false);
     
     
    Thanks,
    Gihan
  • André Arnaud de Calavon Profile Picture
    300,911 Super User 2025 Season 2 on at
    Hi Gihan,
     
    What is the current behavior? Does it overwrite the price with a default from the trade agreements? You are copying the buffer, which initially has the previous line's sales price. 
    Probably the method salesLineIns.createLine(true, true, true, true, true, false) is still overwriting the price, or it was changed before this method? You can use the debugger and monitor when the sales price gets changed. Then you might know the cause and can work around it.
  • Verified answer
    Jonas "Jones" Melgaard Profile Picture
    4,899 Most Valuable Professional on at
    I had a small play with a debugger, just out of curiosity. It looks to be an issue with the method salesLineType.initDimensionsSpecificDefaulting, that resets the price or researches for price agreements regardless of the arguments used. If it's a bug or not I don't know.
     
    The easy work-around is to call the InventTable init method manually and retransfer the prices afterwards.
     
    Consider the following code, it might aid you in your debugging session. The code-snippet function in my browser is not working, so I have made a gist: https://gist.github.com/jofme/b9b5275619d58dde94f7582a3041aa85
     
    Do keep in mind that I haven't tested this other than checking the prices looked about the same.
     
     

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans