Skip to main content
Answer

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

  • January 19, 2023
  • 1 reply
  • 631 views

Michael Ndungi
Varsity I
Forum|alt.badge.img

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);
}
}
}
}

 

Best answer by Yuriy Zaletskyy

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.

1 reply

Yuriy Zaletskyy
Jr Varsity I
Forum|alt.badge.img+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.