How to pass line item custom field value to sales

2019-03-03 18:21发布

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

标签: acumatica
2条回答
太酷不给撩
2楼-- · 2019-03-03 18:38

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;
});
查看更多
叛逆
3楼-- · 2019-03-03 19:03

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.

查看更多
登录 后发表回答