Solved

Unable to cast object of type 'APDocumentResult' to type 'PX.Data.PXResult`1[PX.Objects.AP.APDocumentEnq+APDocumentResult]'

  • 19 January 2023
  • 1 reply
  • 409 views

Userlevel 4
Badge

Getting the above error in vendors details; Upgraded from 2020r2 to 2022r2.

what could be the issue?

kindly assist, all responses will be highly appreciated.

 

 

 

 

see full code below;

using System;
using System.Collections.Generic;
using System.Collections;
using PX.Data;
using PX.Objects.GL;
using PX.Objects.CS;
using PX.Objects.CM;
using PX.Objects;
using PX.Objects.AP;

namespace PX.Objects.AP
{
public class APDocumentEnq_Extension : PXGraphExtension<APDocumentEnq>
{


public PXSelectOrderBy<APDocumentEnq.APDocumentResult, OrderBy<Asc<APDocumentEnq.APDocumentResult.docDate>>> Documents;
protected virtual IEnumerable documents()
{
decimal decCurrRunningBal = 0;
decimal decRunningBal = 0;
Dictionary<string, decimal> curydict = new Dictionary<string, decimal>();

BqlCommand query = Base.Documents.View.BqlSelect;
PXView view = new PXView(Base, true, query, Base.Documents.View.BqlDelegate);

int intStartRow = PXView.StartRow;
int intTotalRows = 0;



List<Object> list = view.Select(PXView.Currents, PXView.Parameters, PXView.Searches, PXView.SortColumns, PXView.Descendings, PXView.Filters, ref intStartRow, PXView.MaximumRows, ref intTotalRows);
PXView.StartRow = 0;

foreach (PXResult<APDocumentEnq.APDocumentResult> item in list)
{
APDocumentEnq.APDocumentResult row = item;
APRegisterExt registerExt = this.Base.Documents.Cache.GetExtension<APRegisterExt>(row);

//KES Running Balance
decRunningBal += row.OrigDocAmt ?? 0;
//ed
//Foreign Running Balance
if (row.CuryID != "KWH")
{
if (curydict.ContainsKey(row.CuryID))
{
curydict[row.CuryID] += row.CuryOrigDocAmt ?? 0;
decCurrRunningBal = curydict[row.CuryID];
}
else
{
curydict[row.CuryID] = row.CuryOrigDocAmt ?? 0;
decCurrRunningBal = curydict[row.CuryID];
}

//ed decCurrRunningBal += row.CuryOrigDocAmt ?? 0;

}
registerExt.UsrCurrencyRbal = decCurrRunningBal;
registerExt.UsrVenderbal = decRunningBal;
}
return list;

}
//CODE FOR DISPLAYING DOCUMENT TAX
protected void APDocumentResult_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
APDocumentEnq.APDocumentResult row = (APDocumentEnq.APDocumentResult)e.Row;
if(row == null) return;
APRegisterExt extObj = cache.GetExtension<APRegisterExt>(row);
APInvoice invoiceObj = PXSelect<APInvoice, Where<APInvoice.refNbr, Equal<Required<APInvoice.refNbr>>,
And<APInvoice.docType, Equal<Required<APInvoice.docType>>>>>.Select(this.Base, row.RefNbr, row.DocType);

if(invoiceObj != null)
{
extObj.UsrTaxAmt = invoiceObj.CuryTaxTotal;
//cache.SetValue<APRegisterExt.usrTaxAmt>(e.Row,invoiceObj.CuryTaxTotal);
if(invoiceObj.CuryTaxTotal> 0) extObj.UsrTwopercent = (invoiceObj.CuryTaxTotal * 0.125m);
//var result = invoiceObj.CuryTaxTotal * 0.125m;
//if(invoiceObj.CuryTaxTotal> 0) cache.SetValue<APRegisterExt.usrTwopercent> (e.Row,result);
}
}
}
}

 

icon

Best answer by Yuriy Zaletskyy 22 January 2023, 09:00

View original

1 reply

Userlevel 5
Badge +3

This error message is indicating that the type of the object that you are trying to cast to PXResult<APDocumentEnq.APDocumentResult> is not compatible with that type. It seems that the type of the object that you are trying to cast is APDocumentEnq.APDocumentResult. You should change the type of the object that you are trying to cast to PXResult<APDocumentEnq.APDocumentResult> in the following line

foreach (PXResult<APDocumentEnq.APDocumentResult> item in list)

Replace

foreach (PXResult<APDocumentEnq.APDocumentResult> item in list)

with

foreach (APDocumentEnq.APDocumentResult item in list)

Additionally, you should also change the following line

APDocumentEnq.APDocumentResult row = item;

to

var row = item;

Also, you should check if the 'APRegisterExt' DAC extension is created in your project and check if the 'UsrCurrencyRbal' and 'UsrVenderbal' fields are added to the 'APRegisterExt' DAC.

After this modification, your code should work fine.

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