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)

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

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,069 Super User 2025 Season 2 on at

    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.  

  • Shyam Mani Profile Picture
    331 on at

    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

  • Verified answer
    Von Profile Picture
    108 on at

    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*/
  • André Arnaud de Calavon Profile Picture
    301,069 Super User 2025 Season 2 on at

    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.

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