To achieve dynamic pricing in Microsoft Dynamics 365 Finance & Operations (D365 F&O) where the Sales Order (SO) line price is automatically updated based on the Purchase Order (PO) price plus a markup, you can follow these steps:
Step-by-Step Solution
-
Create a Custom Field for Markup:
-
Develop a Custom Workflow or Extension:
-
Event Handler for PO Confirmation:
-
Update SO Line Price:
Example Code Snippet
Here's an example of how you might implement the event handler and price update logic in X++:
[EventHandler(eventType = FormDataSourceEventType::ValidatedField, formDataSource = tableStr(PurchTable), field = fieldStr(PurchTable, Confirmed))]
public static void PurchTable_OnConfirmedFieldValidated(FormDataSource sender, FormDataSourceEventArgs e)
{
PurchTable purchTable = sender.cursor();
PurchLine purchLine;
SalesLine salesLine;
SalesTable salesTable;
MarkupPercentage markup;
// Loop through all PO lines
while select purchLine
where purchLine.PurchId == purchTable.PurchId
{
// Find the linked SO line
select firstOnly salesLine
where salesLine.PurchId == purchLine.PurchId
&& salesLine.ItemId == purchLine.ItemId;
if (salesLine)
{
// Retrieve the markup percentage
markup = salesLine.MarkupPercentage;
// Calculate the new SO line price
salesLine.SalesPrice = purchLine.PurchPrice + (purchLine.PurchPrice * markup / 100);
// Update the SO line
salesLine.doUpdate();
}
}
}