Skip to main content

Notifications

Microsoft Dynamics AX forum
Answered

Proper way of adding SalesLine using X++?

Posted on by 95

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);
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 290,186 Super User 2024 Season 2 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 95 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... 290,186 Super User 2024 Season 2 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.  

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,186 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,996 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans