0
votes

I added a custom field for vendorid on the SO Line. (Yes, I know there is one there, but we are building some new logic). I've added the integer field and it appears on the grid fine. I'm trying to get a lookup of vendors. I started with this

Where<AP.Vendor.type, NotEqual<BAccountType.employeeType>>>))]

and then tried

    Where<BAccountR.type, Equal<BAccountType.companyType>, 
        Or<AP.Vendor.type, NotEqual<BAccountType.employeeType>>>>), 
    Visibility = PXUIVisibility.SelectorVisible, CacheGlobal = true, Filterable = true)]

It got me a lookup on new records, but then when I save and try to open any sales order, I get an error that says "Error: An error occurred during the processing of the field InventoryID: Specified cast is not valid.." which makes no sense to me. But if I remove the above it works, so seems like that must be the issue.

Stack Trace as requested: Error: Error: An error occurred during processing of the field InventoryID: Specified cast is not valid..

    Raised At: 2/24/2020 6:47:58 PM     Screen: SO.30.10.00         

Details:
2/24/2020 6:47:58 PM Error:
Error: An error occurred during processing of the field InventoryID: Specified cast is not valid..

System.InvalidCastException: Specified cast is not valid.
   at System.Data.SqlClient.SqlBuffer.get_Int32()
   at PX.Data.PXDataRecord.GetInt32(Int32 i)
   at PX.Data.PXDBIntAttribute.RowSelecting(PXCache sender, PXRowSelectingEventArgs e)
   at PX.Data.PXCache.OnRowSelecting(Object item, PXDataRecord record, Int32& position, Boolean isReadOnly)
   at PX.Data.PXCache.OnRowSelecting(Object item, PXDataRecord record, Int32& position, Boolean isReadOnly)
   at PX.Data.PXCache`1.Select(PXDataRecord record, Int32& position, Boolean isReadOnly, Boolean& wasUpdated)
   at PX.Data.PXView.GetResult(Object[] parameters, PXFilterRow[] filters, Boolean reverseOrder, Int32 topCount, PXSearchColumn[] sorts, Boolean& overrideSort, Boolean& extFilter)
   at PX.Data.PXView.Select(Object[] currents, Object[] parameters, Object[] searches, String[] sortcolumns, Boolean[] descendings, PXFilterRow[] filters, Int32& startRow, Int32 maximumRows, Int32& totalRows)
   at PX.Objects.SO.SOOrderEntry.transactions()
   at _CustomMethod(Object , Object[] )
   at PX.Data.PXView.InvokeDelegate(Object[] parameters)
   at PX.Data.PXView.Select(Object[] currents, Object[] parameters, Object[] searches, String[] sortcolumns, Boolean[] descendings, PXFilterRow[] filters, Int32& startRow, Int32 maximumRows, Int32& totalRows)
   at PX.Data.PXGraph.ExecuteSelect(String viewName, Object[] currents, Object[] parameters, Object[] searches, String[] sortcolumns, Boolean[] descendings, PXFilterRow[] filters, Int32& startRow, Int32 maximumRows, Int32& totalRows) 

Anyone have any thoughts?

2
Could you add a stack trace for the error? It may shed some light on the error. Full field definition may help as well - Dmitrii Naumov
[PXDBInt] [PXUIField(DisplayName="Vendor ID")] [AP.Vendor(typeof(Search<BAccountR.bAccountID, Where<AP.Vendor.type, NotEqual<BAccountType.employeeType>>>))] - T-Rav
Are you sure this is the only thing that can cause the issue? Maybe there is something else. - Dmitrii Naumov
Well, if I take that off, it works fine. If I add it then it fails. I thought maybe my code so I purged all the code out of that customization and just published that one and I still get the problem. - T-Rav
So, so fun I took off all the customizations and then added a field to the poorder table with the same attributes. Same error. It's something about that lookup that doesn't work. - T-Rav

2 Answers

5
votes

TL;DR;

Remove PXDBInt attribute from the field.


The issue here is not with Where condition but with attributes definition for the field.

 [PXDBInt]  
 [PXUIField(DisplayName="Vendor ID")] 
 [AP.Vendor(typeof(Search<BAccountR.bAccountID, Where<AP.Vendor.type,
 NotEqual<BAccountType.employeeType>>>))]

Actually, here you have DBField attribute twice. You have PXDBIntAttribute and Vendor attribute that contains PXDBIntAttribute inside. enter image description here

Because of that the framework has the wrong fields to db columns mapping resulting in that strange error.

If you use Visual studio, I recommend you to try Acuminator extension https://marketplace.visualstudio.com/items?itemName=Acumatica.Acuminator

It highlights that type of errors enter image description here

1
votes

Too long for a comment, but more of a suggestion than an "answer". Try building your own PXSelector. I have a custom DAC that needs to store two vendors, and I had to abandon the AP.Vendor attribute for a custom PXSelector for mine to work. This is one of mine. In my case, I need to be able to see which one is defined as the Preferred Vendor for the warehouse, and I only want to see vendors associated with my InventoryID. SSINItemBranch is a custom DAC that is also available in the scope of this DAC's usage. The point is, use this as an example if you need one to try creating your own from scratch. If this isn't how you want to accomplish the task, at least you might isolate if the problem is a use case of the AP.Vendor attribute or something else.

[PXSelector(
        typeof(Search2<
            Vendor.bAccountID,
            InnerJoin<POVendorInventory,
                On<POVendorInventory.vendorID, Equal<Vendor.bAccountID>,
                And<POVendorInventory.inventoryID, Equal<Current<SSINItemBranch.inventoryID>>>>,
            LeftJoin<INItemSite, On<INItemSite.inventoryID, Equal<POVendorInventory.inventoryID>,
                And<INItemSite.preferredVendorID, Equal<POVendorInventory.vendorID>,
                And<INItemSite.preferredVendorLocationID, Equal<POVendorInventory.vendorLocationID>,
                And<INItemSite.preferredVendorOverride, Equal<True>>>>>>>,
                Where<Vendor.type, Equal<BAccountType.vendorType>>>),
        typeof(Vendor.acctCD),
        typeof(Vendor.acctName),
        typeof(POVendorInventory.vendorLocationID),
        typeof(INItemSite.preferredVendorOverride),
        typeof(POVendorInventory.vendorInventoryID),
        typeof(POVendorInventory.vLeadTime),
        SubstituteKey = typeof(Vendor.acctCD),
        DescriptionField = typeof(Vendor.acctName),
        Filterable = true
        )]