Announcements
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);
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.
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*/
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
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.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,186 Super User 2024 Season 2
Martin Dráb 227,996 Super User 2024 Season 2
nmaenpaa 101,148