0
votes

I have a custom DAC, 'BranchPaymentDefault.' One of the fields is a lookup to the 'Account' object.

Whenever I open the page, or try to use the selector to select an Account, I get an error saying 'Specified Cast Not Valid

I tried using the PXSelector attribute instead of Account attribute, but I get the same error.

DAC

namespace VendorMasterPaymentDefaults
{

[Serializable] public class BranchPaymentDefault : IBqlTable {

[PXDBInt(IsKey = true)]
[PXDefault()]
[PXUIField(DisplayName = "Branch")]
[Branch()]
public virtual Int32? BranchID { get; set; }
public abstract class branchID : IBqlField { }

[PXDBInt(IsKey = true)]
[PXDefault(typeof(Vendor.bAccountID))]
[PXUIField(DisplayName = "Vendor")] 
[PXParent(typeof(Select<Vendor, Where<Vendor.bAccountID, Equal<Current<BranchPaymentDefault.vendorID>>>>))]
public virtual Int32? VendorID { get; set; }
public abstract class vendorID : IBqlField {  }  

[Account(typeof(Account.accountID), IsKey = false, DisplayName = "Account")]
public virtual int? AccountID { get; set; }
public abstract class accountID : IBqlField { }

[PXDBDecimal]
[PXDefault()]
[PXUIField(DisplayName = "Allotment Amt")]
public virtual decimal? AllotmentAmt { get; set; } 
public abstract class allotmentAmt : IBqlField { }  

[PXDBString(IsUnicode = true)]
[PXUIField(DisplayName = "Allotment Type")]
[PXDefault(allotmentType.Values.Percentage)]
[PXStringList(new string[]{ allotmentType.Values.Percentage, allotmentType.Values.FixedAmt },
              new string[]{ allotmentType.Values.UI.Percentage, allotmentType.Values.UI.FixedAmt })]
public virtual string AllotmentType { get; set; }
public abstract class allotmentType : IBqlField 
{
   public class Values
   {
     public const string Percentage = "PCT";
     public const string FixedAmt = "FIX";

     public class UI
     {
        public const string Percentage = "Percent";
        public const string FixedAmt = "Fixed"; 
     }
   }       
}


[PXDBCreatedByID()] 
public virtual Guid? CreatedByID { get; set; }    
public abstract class createdByID : IBqlField { } 

[PXDBCreatedDateTime]  
public virtual DateTime? CreatedDateTime { get; set; } 
public abstract class createdDateTime : IBqlField { }

[PXDBLastModifiedByID] 
public virtual Guid? LastModifiedByID { get; set; }
public abstract class lastModifiedByID : IBqlField { } 

[PXDBLastModifiedDateTime]
public virtual DateTime? LastModifiedDateTime { get; set; }
public abstract class lastModifiedDateTime : IBqlField { }

} }

GRAPH

namespace PX.Objects.AP
{
 public class VendorMaint_Extension : PXGraphExtension<VendorMaint>
 {


public PXSelect<BranchPaymentDefault, 
Where<BranchPaymentDefault.vendorID, 
Equal<Current<BAccount.bAccountID>>>> BranchPaymentDefaults;


  }
}
1
Can you please add the SQL Table's declaration to the question? - Samvel Petrosov
CREATE TABLE [dbo].[BranchPaymentDefault]( [BranchID] [int] NOT NULL, [VendorID] [int] NOT NULL, [AllotmentAmt] [decimal](18, 0) NOT NULL, [AllotmentType] [varchar](3) NOT NULL, [CreatedByID] [uniqueidentifier] NOT NULL, [CreatedDateTime] [smalldatetime] NOT NULL, [LastModifiedByID] [uniqueidentifier] NOT NULL, [LastModifiedDateTime] [smalldatetime] NOT NULL, [AccountID] [int] NOT NULL ) - Adam St.Hilaire
I tried using the following attributes for the Account ID Field.. [PXDefault] [Account( null, typeof(Search<Account.accountID, Where<Match<Current<AccessInfo.userName>>>>), DisplayName = "Account", DescriptionField = typeof(Account.description), Visibility = PXUIVisibility.SelectorVisible)] [PXRestrictor(typeof(Where<Account.type, Equal<AccountType.expense>>), PX.Objects.GL.Messages.YTDNetIncomeMayBeLiability)] public virtual Int32? AccountID{ get; set; } public abstract class accountID: PX.Data.BQL.BqlInt.Field<accountID> { } - Adam St.Hilaire
Usually "Specified cast is not valid" error means that you have specified different data types for the field in the Selector/Field Declaration/Database. Try to removing the selector at all and working with the raw field. If that works, then we need to understand the exact problem with selector, otherwise, there is a problem either in DAC or Database Table. - Samvel Petrosov
I removed the [Account] attribute, and I still get the error. The DB type of AccountID is INT, and I'm using Int32 in my DAC. - Adam St.Hilaire

1 Answers

0
votes

The problem was actually with the BranchAttribute. For some reason, using the parameterless constructor was throwing the exception.