Breaking News

c# – Acumatica upgrade from 18.210 to 18.217 (Unable to cast object of type ‘PX.Data.PXResult`2[PX.Objects.FS.FSServiceOrder,PX.Objects.AR.Customer]’-Exceptionshub

Questions:

The source code of the button action is

public PXAction CreateSalesOrder;
        [PXUIField(DisplayName = "Create Sales Order", Enabled = true, MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
        [PXProcessButton]

        public virtual IEnumerable createSalesOrder(PXAdapter adapter)
        {
            foreach (FSServiceOrder fso in adapter.Get())
            {
                Customer cust = (Customer)PXSelect>>>.Select(this.Base);
                if (cust == null)
                {
                    string exc = "Invalid customer ID";
                    throw new PXException(exc);
                }
                yield return fso;
            }
            SOOrderEntry docgraph = PXGraph.CreateInstance();
            PXLongOperation.StartOperation(Base, delegate ()
            {
                Customer customer = (Customer)PXSelect>>>.Select(this.Base);
                FSServiceOrder fsServiceORderRow = this.Base.ServiceOrderRecords.Current;
                FSSODetPart rows = this.Base.ServiceOrderDetParts.Current;

                CurrencyInfo info = PXSelect>>>.Select(this.Base);
                info.CuryInfoID = null;
                bool createso = false;
                foreach (FSSODetPart parts in SelectItems(fsServiceORderRow.RefNbr))
                {
                    if (parts == null)
                    {
                        createso = false;
                    }
                    else
                    {
                        createso = true;
                    }
                }

                if (createso == true)
                {
                    SOOrder doc = new SOOrder();                    
                    doc.OrderType = "SM";
                    doc = docgraph.Document.Insert(doc);
                    doc.OrderDate = fsServiceORderRow.OrderDate;
                    doc.CustomerRefNbr = fsServiceORderRow.RefNbr;
                    doc.CustomerOrderNbr = fsServiceORderRow.CustPORefNbr;
                    nbr = fsServiceORderRow.RefNbr;
                    doc.OrderDesc = fsServiceORderRow.DocDesc;
                    doc.TermsID = customer.TermsID;
                    doc.CustomerID = fsServiceORderRow.CustomerID;
                    doc = docgraph.Document.Update(doc);

                    foreach (FSSODetPart parts in SelectItems(fsServiceORderRow.RefNbr))
                    {
                        if (parts == null) return;
                        SOLine tran = new SOLine();
                        tran = docgraph.Transactions.Insert(tran);
                        if (tran != null)
                        {
                            tran.InventoryID = parts.InventoryID;
                            tran.SubItemID = parts.SubItemID;
                            tran.OrderQty = parts.OrderQty;
                            tran.UOM = parts.UOM;
                            tran.CuryUnitPrice = parts.CuryUnitPrice;
                            tran.TaxCategoryID = parts.TaxCategoryID;
                            tran.SiteID = parts.SiteID;
                            tran.LocationID = parts.LocationID;
                            tran.IsFree = parts.IsFree;
                            tran.ProjectID = parts.ProjectID;
                            tran.TaskID = parts.TaskID;
                            tran.ManualPrice = parts.ManualPrice;
                        }
                        tran = docgraph.Transactions.Update(tran);
                    }
                    docgraph.Save.Press();
                    docgraph.Document.Current = docgraph.Document.Search(doc.OrderNbr, doctype);                    
                }
            });
        }```
While the error being displayed in trace is

19/02/2020 7:53:31 AM Error:
Unable to cast object of type ‘PX.Data.PXResult`2[PX.Objects.FS.FSServiceOrder,PX.Objects.AR.Customer]’ to type ‘PX.Objects.FS.FSServiceOrder’.

at PX.Objects.FS.ServiceOrderEntry_Extension.d__3.MoveNext()
at PX.Data.PXAction1.d__32.MoveNext()
at PX.Data.PXAction
1.d__32.MoveNext()
at PX.Data.PXAction1.d__32.MoveNext()
at PX.Data.PXAction
1.d__32.MoveNext()
at PX.Web.UI.PXBaseDataSource.tryExecutePendingCommand(String viewName, String[] sortcolumns, Boolean[] descendings, Object[] searches, Object[] parameters, PXFilterRow[] filters, DataSourceSelectArguments arguments, Boolean& closeWindowRequired, Int32& adapterStartRow, Int32& adapterTotalRows)
at PX.Web.UI.PXBaseDataSource.ExecuteSelect(String viewName, DataSourceSelectArguments arguments, PXDSSelectArguments pxarguments)

I am still new to acumatica. I'll really appreciate the help

How to&Answers:

Based on the information you provided in the comments, try with this alternative approach for the “Invalid Customer ID” validation:

Replace this section:

 foreach (FSServiceOrder fso in adapter.Get())
            {
                Customer cust = (Customer)PXSelect>>>.Select(this.Base);
                if (cust == null)
                {
                    string exc = "Invalid customer ID";
                    throw new PXException(exc);
                }
                yield return fso;
            }

With this one:

FSServiceOrder currentServiceOrder = this.Base.ServiceOrderRecords.Current;

if (currentServiceOrder != null && currentServiceOrder.CustomerID != null)
{
                Customer cust = PXSelect>>>.Select(this.Base, currentServiceOrder.CustomerID);
                if (cust == null)
                {
                    string exc = "Invalid customer ID";
                    throw new PXException(exc);
                }
}

About rankhawks

Check Also

Python 3 Programming: Beginner To Pro Masterclass

We are on a mission to create the most complete Python programming guide in the …

Learn Social Engineering From Scratch

Basic IT Skills No Linux, programming or hacking knowledge required. Computer with a minimum of …

Complete Python Programming From Basics To Advance Level

Complete Python Programming From Basics To Advance Level Learn python in detail covering Basics and …

Data Visualization On The Browser With Python And Bokeh

Data Visualization On The Browser With Python And Bokeh A complete guide on creating beautiful …

Learn Python – Python Programming For Beginners From Scratch

Learn Python – Python Programming For Beginners From Scratch Python is a highly paid programming …

Leave a Reply

Your email address will not be published. Required fields are marked *