Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Proper way of adding SalesLine using X++?

(1) ShareShare
ReportReport
Posted on by 108

Hi, 

I have my working code already and it is adding salineLine correctly but I'm not sure if this is the right way because when I changed the Sales Quantity value of the auto populated salesline using the interface the SalesPrice return to its original value which is the Sales Base Price.

Below is my code

	SalesLine	salesLine;
	InventDim	inventDim;
	InventTable	inventTable;
	
	salesLine.clear();
	inventDim = null;
	salesLine.initValue();

	salesLine.SalesId = salesTable.SalesId;
	salesLine.initFromSalesTable(salesTable);

	salesLine.ItemId = '123';	
	
	inventTable = InventTable::find(salesLine.ItemId);
	salesLine.initFromInventTable(inventTable);

	inventDim.initFromInventTable(inventTable);
	salesLine.InventDimId = InventDim::findOrCreate(inventDim).InventDimId;

	salesLine.SalesQty =  1;

	salesLine.SalesPrice = 3200.00;
	
	salesLine.LineAmount = salesLine.calcLineAmount();
	
	salesLine.createLine(true,true,false,true);

*This post is locked for comments

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,494 Super User 2025 Season 1 on at
    RE: Proper way of adding SalesLine using X++?

    Hi Von,

    Thanks for the feedback. You you mind to mark the correct answer(s) (may be your own) so the thread will get the status answered? Other persons with the same question will be directed to the verified answers initially.

  • Verified answer
    Von Profile Picture
    Von 108 on at
    RE: Proper way of adding SalesLine using X++?

    I ended up creating trade agreements for each product and set the default price there and then add the below code into my code to use the trade agreement selling price.

    salesLine.setPriceDisc(inventDim)

    One of our requirements is to define the default price of each Product Variant and I'm thinking that the solution for this is by using trade agreements.

    Below is my code for creating SaleLine

    SalesLine	salesLine;
    InventDim	inventDim;
    SalesId		salesId = '100001'
    ItemId		itemId = 'ITM1001';
    ConfigId	configId = 'CFG1001';
    salesLine.initValue();		
    
    /* Init SalesLine from SalesTable*/
    salesLine.SalesId = salesId;
    salesLine.initFromSalesTable(salesTable);
    /* End*/
    
    /* Set SalesLine Item*/
    salesLine.ItemId = itemId;
    /* End*/
    
    /* Set Retail Variant Id*/
    inventDim.configId = configId;
    inventDim = InventDim::findOrCreate(inventDim);
    salesLine.RetailVariantId = InventDimCombination::find(salesLine.ItemId,inventDim.InventDimId).RetailVariantId;
    /* End*/
    
    /* Set Inventory Dimension Id*/
    inventDim.clear();
    inventTable = InventTable::find(itemId);
    inventDim.initFromInventTable(inventTable);
    inventDim.configId = configId;
    inventDim = InventDim::findOrCreate(inventDim);
    salesLine.initFromProductDimensions(inventDim);
    salesLine.InventDimId = inventDim.inventDimId;
    /* End*/
    
    /* Set Sales Quantity*/
    salesLine.SalesQty =  1;
    /* End*/
    
    /* Look for trade agreement if not found base selling price will be use*/
    salesLine.setPriceDisc(inventDim);
    /* End*/
    
    /* Create SalesLine*/
    salesLine.CreateLine(NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes);
    /* End*/
  • Shyam Mani Profile Picture
    Shyam Mani 331 on at
    RE: Proper way of adding SalesLine using X++?

    Hi Von,

    Please check modified/modified field method of SalesQty field at table and DS level. There will be some clue. Also check active method and validatewrite with regard to SalesQty.

    Regards,

    Shyam

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,494 Super User 2025 Season 1 on at
    RE: Proper way of adding SalesLine using X++?

    Hi Von,

    There is some logic in AX2012 which will set some table values related to the sales line where AX knows if there is a manual price override. This is not set within your salesLine creation method. I don't know the exact coding or where the coding is used. Probably you can use the debugger and change some prices manually on the form to see which coding is used to maintain. If you found it, you can use this mechanism in your coding.  

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans