Solved

Copy value from Sales Quote to Sales Order

  • 4 January 2023
  • 3 replies
  • 259 views

Userlevel 3
Badge

Hello Everyone,

I have override the Convert To Order action in the Sales Quotes screen, and copying the line field value from the Sales Quote to Sales Order line with the below code.

Value are getting copied properly but caches are not updating as expected, when try to edit any other value and try to save it is giving me an error.

 

Here is the code, can anyone review and share your thoughts.

 

 [PXOverride]
public IEnumerable createSalesOrder(PXAdapter adapter, Func<PXAdapter, IEnumerable> baseMethod)
{
SOOrderEntry SOGraph = PXGraph.CreateInstance<SOOrderEntry>();

PXGraph.InstanceCreated.AddHandler(delegate (SOOrderEntry graph)
{

graph.RowUpdated.AddHandler<SOLine>(delegate (PXCache sender, PXRowUpdatedEventArgs e)
{
SOLine objSOLine = e.Row as SOLine;
if (objSOLine != null)
{
foreach (CROpportunityProducts item in Base.Products.Select().FirstTableItems.ToList().Where(x => x.InventoryID == objSOLine.InventoryID))
{
if (item.POCreate == true)
{
sender.SetValueExt<SOLine.pOCreate>((object)objSOLine, true);
sender.SetValueExt<SOLine.pOSource>((object)objSOLine, "D");
}
}
}
});

});
return baseMethod(adapter);
}

 

 

icon

Best answer by nsmith51 26 February 2023, 18:15

View original

3 replies

Userlevel 3
Badge

Here is the code, finally I figured it out!!

 


public class QuoteMaintExt : PXGraphExtension<QuoteMaint.CRCreateSalesOrderExt, QuoteMaint>
{
public static bool IsActive() => true;

[PXOverride]
public IEnumerable createSalesOrder(PXAdapter adapter, Func<PXAdapter, IEnumerable> baseMethod)
{
PXGraph.InstanceCreated.AddHandler(delegate (SOOrderEntry graph)
{
graph.RowUpdated.AddHandler<SOOrder>(delegate (PXCache sender, PXRowUpdatedEventArgs e)
{
SOOrder objSOOrder = e.Row as SOOrder;
if (objSOOrder != null)
{
// ==> the below code is for to copy the Header Quote fields to Sales Order Header fields
sender.SetValue<SOOrderExt.usrHeaderNotes1>((object)objSOOrder, objQuoteExt.UsrHeaderNotes1);
sender.SetValue<SOOrderExt.usrHeaderNotes2>((object)objSOOrder, objQuoteExt.UsrHeaderNotes2 );

}
});

graph.RowUpdated.AddHandler<SOLine>(delegate (PXCache sender, PXRowUpdatedEventArgs e)
{
SOLine objSOLine = e.Row as SOLine;
if (objSOLine != null)
{
SOLineExt objLineExt = objSOLine.GetExtension<SOLineExt>();
foreach (CROpportunityProducts item in Base.Products.Select().FirstTableItems.ToList().Where(x => x.InventoryID == objSOLine.InventoryID))
{


// ==> Below code is copy to Quote line items to Sales Order line items
CROpportunityProductsExt objItemExt = item.GetExtension<CROpportunityProductsExt>();

sender.SetValue<SOLineExt.usrNotes1>((object)objSOLine, objItemExt.UsrNotes1);
sender.SetValue<SOLineExt.usrNotes2>((object)objSOLine, objItemExt.UsrNotes2);
sender.SetValue<SOLineExt.usrNotes3>((object)objSOLine, objItemExt.UsrNotes3);

}
}
});

});
return baseMethod(adapter);
}


}


 

Userlevel 7
Badge

Thank you for sharing your solution with the community @nsmith51 !

Userlevel 4
Badge

Hi nsmith51,

 

Thanks so much for your solution.  Being able to add an event handler to a Graph instance programmatically is something I didn’t even know you could do.  Have replicated in one of my customisations.  Works a treat!

 

 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved