How to pass line item custom field value to sales order from opportunity?

℡╲_俬逩灬. 提交于 2019-12-04 06:30:53

问题


I have a custom line number field in opportunity product tab for customer to re-sequence the selected products and the grid is sorted on custom field value.

I am trying to pass the value from opportunity to sales order which also having a similar field.

the following code i have tried and it did not work

            PXGraph.InstanceCreated.AddHandler<SOOrderEntry>((graph) =>
            {
                graph.RowUpdated.AddHandler<SOLine>((cache, args) =>
                    {

                        CROpportunityProducts product = (adapter.View.Graph as OpportunityMaint).Products.Current;
                        CROpportunityProductsExtNV productext = PXCache<CROpportunityProducts>.GetExtension<CROpportunityProductsExtNV>(product);
                        SOLine soline = (SOLine)args.Row;
                        SOLineExtNV solineext = PXCache<SOLine>.GetExtension<SOLineExtNV>(soline);
                        solineext.UsrLineNo = productext.UsrLineNo;

                    });
            });

The following piece of code returns same value for all line numbers


回答1:


You can implement RowInserting Event handler as below:

graph.RowInserting.AddHandler<SOLine>((cache, args) =>
{
    var soLine = (SOLine)args.Row;
    CROpportunityProducts opProduct = PXResult<CROpportunityProducts>.Current;
    SOLineExtNV soLineExt = PXCache<SOLine>.GetExtension<SOLineExtNV>(soLine);
    CROpportunityProductsExtNV opProductExt = PXCache<CROpportunityProducts>.GetExtension<CROpportunityProductsExtNV>(opProduct);
    soLineExt.UsrLineNo = opProductExt.UsrLineNo;
});



回答2:


wish they could split up the call to create the order and the call to insert the lines to make it easier to customize. We have done something similar. Here is a sample from what I tested using a graph extension and overriding the DoCreateSalesOrder call in the opportunitymaint graph. (This assumes the select on products is the same order the transaction on the sales order were inserted. I am sure there could be a better answer, but this is an example I have handy.)

public class CROpportunityMaintExtNV : PXGraphExtension<OpportunityMaint>
{
    [PXOverride]
    public virtual void DoCreateSalesOrder(Action del)
    {
        try
        {
            del();
        }
        catch (PXRedirectRequiredException redirect)
        {
            var products = this.Products.Select().ToArray();

            int rowCntr = 0;
            foreach (SOLine soLine in ((SOOrderEntry)redirect.Graph).Transactions.Select())
            {
                // Assumes inserted rows in same order as products listed (default should be the key)

                //Current product
                CROpportunityProducts currentProduct = products[rowCntr];
                var productExtension = currentProduct.GetExtension<CROpportunityProductsExtNV>();

                ((SOOrderEntry) redirect.Graph).Transactions.Cache.SetValueExt<SOLineExtNV.usrLineNo>(soLine, productExtension.UsrLineNo);

                rowCntr++;
            }

            throw redirect;
        }
    }
}

The problem you had with your code is the Current product was always the same which resulted in the same value.



来源:https://stackoverflow.com/questions/42352177/how-to-pass-line-item-custom-field-value-to-sales-order-from-opportunity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!