Search code examples
listpowerapps

PowerApps - "is this value in or not in an existing Microsoft List?"


I am utterly baffled by this.

My goal is to create a sequence that basically says "If you don't find an appropriate record in this Microsoft List, then create a new one and proceed."

This is the section of code that is vexing me (and even this is just a test to see if I've created the proper conditional -- and I have evidently failed):

          ForAll(ScanDataCollection,
              Notify(LookUp('Spiderfood - Loaner Pool', Tag_Number = Result, Tag_Number));
              If(IsEmpty(LookUp('Spiderfood - Loaner Pool', Tag_Number = Result, Tag_Number)), Notify("not found"))
            ); // ForAll(ScanDataCollection,

The [Notify] command is my attempt to ask "What happens when I feed it different values". When I feed it a value x where x appears in the Tag_Value column of 'Spiderfood - Loaner Pool', then it properly kicks out that same value back. If I feed it an x that does not appear, then the Notify window appears blank. That seems to work, and yet, and yet...

...when I attempt to set up some sort of conditional, then the code appears to run without error, but it doesn't notify me of anything, whether or not x is or is not in the List.

I keep thinking that there must be some super-obvious thing I am missing in the line:

If(IsEmpty(LookUp('Spiderfood - Loaner Pool', Tag_Number = Result, Tag_Number)), Notify("not found"))

I throw myself at your mercy.

Update 1:

The following line always generates a "did not find" value even when I have confirmed the value is in the List:

If(IsEmpty(LookUp('Spiderfood - Loaner Pool', Tag_Number = Result)), Notify("Found item: " & Result), Notify("Did not find item: " & Result));

Update 2:

The following line seems to produce the correct responses for the input, but PowerApps flags this line and declares "The CountRows operation is not supported by this connector" (if so, can I trust it?!):

If(CountRows(Filter('Spiderfood - Loaner Pool', Tag_Number = Result)) > 0, Notify("Found item: " & Result), Notify("Did not find item: " & Result));

Solution

  • Okay, nailed it. Had to tweak a few brain cells to do it, but here is the code, fully functional, and using the right kind of functions:

              ForAll(ScanDataCollection,
                If(IsBlank(LookUp('Spiderfood - Loaner Pool', Tag_Number = Result, Tag_Number)),
                     Notify("Previously unrecorded Loaner Kit item addded to Library.");
                     Collect('Spiderfood - Loaner Pool', {
                       Title: Text(Today()),
                       Tag_Number: TrimEnds(Result),
                       Last_Touched_Location: DD_Location.SelectedText.Value,
                       Last_Touched_Time: TransactionTimestamp_Value
                     });
                  ); // If(IsBlank...
                ); // ForAll(ScanDataCollection,