如何在 LookUp 函数中引用 ThisRecord.Value?

问题描述 投票:0回答:1

我在 OnScan 事件中的 BarcodeReader 内创建了此代码。我试图首先检查扫描的条形码是否存在于名为barcode_inventory的Microsoft列表中,如果存在,它将被添加到名为signed_out的列表中。

我的问题是 ThisRecord.Value 由于某种原因无法在 LookUp 函数内部工作,有什么方法可以在 LookUp 函数中引用它吗?

ForAll(
    Self.Barcodes,
    If(
        !IsBlank(
            LookUp(barcode_inventory,Barcode = Value(ThisRecord.Value), Barcode)
        ),
        Collect(
            signed_out,
            {
                Barcode: Value(ThisRecord.Value),
                Product: Text(LookUp(barcode_inventory,Barcode = Value(ThisRecord.Barcode)).ProductNameSize)
            }
        ),
        Notify("Could not find record.", NotificationType.Error)
    )
)

sharepoint powerapps power-platform
1个回答
0
投票

ForAll 函数创建一个 scope,其中包含您尝试引用的 ThisRecord 对象。但 LookUp 函数也会创建自己的作用域,并且 ThisRecord 始终引用最近的作用域。

如果要引用在 ForAll 函数中创建的作用域,可以使用 As 关键字为其命名,并用该名称引用它:

ForAll(
    Self.Barcodes As TheBarcode,
    If(
        !IsBlank(
            LookUp(barcode_inventory,Barcode = Value(TheBarcode.Value), Barcode)
        ),
        Collect(
            signed_out,
            {
                Barcode: Value(TheBarcode.Value),
                Product: Text(LookUp(barcode_inventory,Barcode = Value(TheBarcode.Barcode)).ProductNameSize)
            }
        ),
        Notify("Could not find record.", NotificationType.Error)
    )
)

顺便说一句,您可以通过使用 With 函数缓存 LookUp 值来提高效率,这样就不必执行两次:

ForAll(
    Self.Barcodes As TheBarcode,
    With(
        { productFromInventory: LookUp(barcode_inventory,Barcode = Value(TheBarcode.Value) },
        If(
            !IsBlank(productFromInventory.Barcode),
            Collect(
                signed_out,
                {
                    Barcode: Value(TheBarcode.Value),
                    Product: Text(productFromInventory.ProductNameSize)
                }
        ),
        Notify("Could not find record.", NotificationType.Error)
    )
)
© www.soinside.com 2019 - 2024. All rights reserved.