Acumatica:在显示字段的视图中检索第一条记录 - 无关的订单Bys

时间:2017-06-08 15:21:39

标签: acumatica

我们创建了一个屏幕和图表,用于存储有关库存项目(INItemLotSerial)的给定序列号的自定义信息。

我希望能够根据最近交易的位置显示序列号的当前位置。 (理想情况下,如果序列号目前在库存中,我也希望能够显示,但这可能是一个不同的问题。)

以下是我对图表的看法:

public PXSelect<INTranSplit, Where<INTranSplit.lotSerialNbr, Equal<Optional<INItemLotSerial.lotSerialNbr>>, 
    And<INTranSplit.inventoryID, Equal<Optional<INItemLotSerial.inventoryID>>>>, OrderBy<Desc<INTranSplit.createdDateTime>>> InventoryLocation;

我在页面上的字段:

<px:PXSegmentMask Enabled="False" AllowEdit="False" runat="server" ID="CstPXSegmentMask5" DataField="InventoryLocation.LocationID" ></px:PXSegmentMask>

我希望该字段抓住第一条记录并忽略其余记录。

但是,当我在SQL Trace中查看生成的SQL时,Acumatica似乎正在添加自己的Order By字段:

exec sp_executesql N'SELECT [INTranSplit].[DocType], [INTranSplit].[TranType], [INTranSplit].[RefNbr], [INTranSplit].[LineNbr], [INTranSplit].[POLineType], [INTranSplit].[TransferType], [INTranSplit].[ToSiteID], [INTranSplit].[ToLocationID], [INTranSplit].[SplitLineNbr], [INTranSplit].[TranDate], [INTranSplit].[InvtMult], [INTranSplit].[InventoryID], [INTranSplit].[SubItemID], [INTranSplit].[CostSubItemID], [INTranSplit].[CostSiteID], [INTranSplit].[SiteID], [INTranSplit].[LocationID], [INTranSplit].[LotSerialNbr], [INTranSplit].[ExpireDate], [INTranSplit].[Released], [INTranSplit].[UOM], [INTranSplit].[Qty], [INTranSplit].[BaseQty], [INTranSplit].[MaxTransferBaseQty], [INTranSplit].[OrigPlanType], [INTranSplit].[IsFixedInTransit], [INTranSplit].[PlanID], [INTranSplit].[TotalQty], [INTranSplit].[TotalCost], [INTranSplit].[AdditionalCost], ( CASE WHEN  ( [INTranSplit].[TotalQty] = .0) THEN  .0 ELSE  ( [INTranSplit].[TotalCost] /  [INTranSplit].[TotalQty]) END), [INTranSplit].[CreatedByID], [INTranSplit].[CreatedByScreenID], [INTranSplit].[CreatedDateTime], [INTranSplit].[LastModifiedByID], [INTranSplit].[LastModifiedByScreenID], [INTranSplit].[LastModifiedDateTime], [INTranSplit].[tstamp], [INTranSplit].[UsrQtyForQC], [INTranSplit].[UsrQtyCoded], [INTranSplit].[UsrQtyCompleted] FROM INTranSplit INTranSplit WHERE (INTranSplit.CompanyID = 2) AND  [INTranSplit].[LotSerialNbr] = @P0 AND [INTranSplit].[InventoryID] = @P1 
ORDER BY [INTranSplit].[DocType], [INTranSplit].[RefNbr], [INTranSplit].[LineNbr], [INTranSplit].[SplitLineNbr], [INTranSplit].[CreatedDateTime] DESC OPTION(OPTIMIZE FOR UNKNOWN) /* IN.21.00.00 */',N'@P0 nvarchar(100),@P1 int',@P0=N'EOSC52270005',@P1=16067

导致首先返回不同的记录,而不是最近的记录。

我如何说服Acumatica运行BQL我要求并按字段删除额外的订单?或者是否有一种完全不同的方法来显示最好的交易地点?

1 个答案:

答案 0 :(得分:0)

如果您需要专门的过滤,我建议在这种特殊情况下使用IEnumerable排序

public IEnumerable inventoryLocation()
{
        PXView select = new PXView(this, true, InventoryLocation.View.BqlSelect);
        Int32 totalrow = 0;
        Int32 startrow = PXView.StartRow;
        List<object> result = select.Select(PXView.Currents, PXView.Parameters, PXView.Searches,
            PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startrow, PXView.MaximumRows, ref totalrow);
        INTranSplit latest = null;
        if (result.Count > 0)
        { 
            //We need to perform a custom order in order to get to the latest record.
            latest = result.First() as INTranSplit;
            foreach (INTranSplit row in result)
            {
                if (latest.CreatedDateTime.Value < row.CreatedDateTime.Value)
                {
                    latest = row;
                } 

            }
        }
        return new List<object> { latest };
}

您将获取所有记录,获取第一条记录,然后查找最新记录。

干杯!