cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Post Prodigy
Post Prodigy

Nested If Condition Problem

Hi,

I have this code which is used in the OnScan property of Bar Code Control,  I am actually scanning only those codes which have selected "S" as a Prefix  for Serial Codes.  and "1S" as Prefix selected for Product and Serial Together bar code.

I am using a dropdown called as Prefix Selector

The Condition is working for "1S"  and it's showing popup if the code is scanned again, it will show Duplicate Scanned, and if the different code is scanned it will show a popup >>> Not a 1S Bar Code Type

Issue:  But the code for "S" creating some issues, if the user scans the serial code, it stores and works good, but if the user scans it again it shows both Popups >> Not a Serial Code and Duplicate Scanned at the same time and if the user scans a different code while "S" is selected, it shows popup >>> Not a 1S Bar Code Type (This is not working as expected, what's wrong is in my statements ??)

 

If(ToggleIssue.Value=false && PrefixSelected.Selected.Title = Left(BarcodeScanner2_3.Value,2),


 
// Left(BarCodeScanner2_3.Value,2) is used because if the user has selected ("1S") Prefix, than it will match with it while scanning and store Serial code and Product information.
 
 

If(IsEmpty(Filter('Barcodes - Test',  BarcodeScanner2_3.Value = Title)), 

 
\\ The Above if condition will checks in the Database if there is an entry or not , at first it will return false and then it will patch the data into the databse, and if the scanned code is scannned again it will show a popup to the user as Already Scanned.
 

   Patch('Barcodes - Test',    // Patch Command
   
   Defaults('Barcodes - Test'),

 

   {
   SerialCode:Right(BarcodeScanner2_3.Value,8),
   'Product Code': Mid(BarcodeScanner2_3.Value,3,10),
   Title:BarcodeScanner2_3.Value,
   'Batch No': BatchSelection.Selected.Title,
   ReceiveCheck: ToggleIssue.Value,
   UserName:MyUser,
   ReceivedSatus: "Yet To Receive",
   When:Today() + Time(Hour(Now()), Minute(Now()),Second(Now()))    
   }
),Set(_DuplicateScan,true)),  // Duplicate Popup

 

If(ToggleIssue.Value=false && PrefixSelected.Selected.Title = Left(BarcodeScanner2_3.Value,1),
 
// Left(BarCodeScanner2_3.Value,1) is used because if the user has selected ("S") Prefix, than it will match with it and store only Serial code information.

 

If(IsEmpty(Filter('Barcodes - Test',  BarcodeScanner2_3.Value = Title)), 

 

   Patch('Barcodes - Test',
   
   Defaults('Barcodes - Test'),

 

   {
   SerialCode: Right(BarcodeScanner2_3.Value,8),
   Title:BarcodeScanner2_3.Value,
   'Batch No': BatchSelection.Selected.Title,
   ReceiveCheck: ToggleIssue.Value,
   UserName:MyUser,
   ReceivedSatus: "Yet To Receive",
   When:Today() + Time(Hour(Now()), Minute(Now()),Second(Now()))    
   }

 

),Set(_DuplicateScan,true),
 

Set(_NotSerialCode,true))   // if the user has selected (1S) and if he tries to scan a serial code, or any other code which does not match, it will show a popup, Not a S  Code
 
,Set(_NotISCode,true)))  // if the user has selected (S) and if he tries to scan a serial code, or any other code which does not match, it will show a popup, Not a 1S  Code

 

  I Need Help @WarrenBelz  @v-siky-msft 

39 REPLIES 39

HI @RandyHayes ,

 

The Above two conditions for the Popup of Not 1S Code and Not Serial Code are working as expected,

but if I scan the correct 1S code or S Code, it's not patching the values in the database / SQL List.


The Code: 

 

If(ToggleIssue.Value=false,

    Switch(PrefixSelected.Selected.Title,
        // if the user has selected (1S) and if he tries to scan a serial code, or any other code which does not match, it will show a popup, Not a 1S  Code
        "1S", Set(_NotISCode, !(PrefixSelected.Selected.Title = Left(BarcodeScanner2_3.Value,2))),
        
        // if the user has selected (S) and if he tries to scan a serial code, or any other code which does not match, it will show a popup, Not a S  Code
        "S", Set(_NotSerialCode, !(PrefixSelected.Selected.Title = Left(BarcodeScanner2_3.Value,1))),

        // Is it a duplicate?
        If(!IsEmpty(Filter('Barcodes - Test',  BarcodeScanner2_3.Value = Title)),
            Set(_DuplicateScan, true), // Duplicate Popup
            
            // ELSE - Patch Command
            UpdateContext({patchedRecord:
                Patch('Barcodes - Test',    
                    Defaults('Barcodes - Test'),
                    {
                        SerialCode:Right(BarcodeScanner2_3.Value,8),
                        Title:BarcodeScanner2_3.Value,
                        'Batch No': BatchSelection.Selected.Title,
                        ReceiveCheck: ToggleIssue.Value,
                        UserName:MyUser, 
                        ReceivedSatus: "Yet To Receive",
                        When:Today() + Time(Hour(Now()), Minute(Now()),Second(Now()))    
                    },
                    If(PrefixSelected.Selected.Title="1S",
                        {'Product Code': Mid(BarcodeScanner2_3.Value,3,10)},
                        {}
                    )
            )
            }
            
                
        )
     )
  )
)

 

Any help? 

@MH3 

Since that is part of an If statement in the Formula, then if there is no record written, then you must be getting the duplicate popup?  Is that the case?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Hi @RandyHayes ,

 

No No, if there is a record in the SP List already then and only than they will get a popup of Already Scanned or Duplicate Record.

 

and there is no such record in the SP List, than it should patch that record.

 

Hope you understand now? 

@MH3 

I might have misunderstood your original logic in your Formula.

Replace with this Formula:

If(ToggleIssue.Value=false,

    Switch(PrefixSelected.Selected.Title,
        // if the user has selected (1S) and if he tries to scan a serial code, or any other code which does not match, it will show a popup, Not a 1S  Code
        "1S", Set(_NotISCode, !(PrefixSelected.Selected.Title = Left(BarcodeScanner2_3.Value,2))),
        
        // if the user has selected (S) and if he tries to scan a serial code, or any other code which does not match, it will show a popup, Not a S  Code
        "S", Set(_NotSerialCode, !(PrefixSelected.Selected.Title = Left(BarcodeScanner2_3.Value,1)))
    );
    
    If(!_NotISCode && !_NotSerialCode,

        // Is it a duplicate?
        If(!IsEmpty(Filter('Barcodes - Test',  BarcodeScanner2_3.Value = Title)),
            Set(_DuplicateScan, true), // Duplicate Popup
            
            // ELSE - Patch Command
            UpdateContext({patchedRecord:
                Patch('Barcodes - Test',    
                    Defaults('Barcodes - Test'),
                    {
                        SerialCode:Right(BarcodeScanner2_3.Value,8),
                        Title:BarcodeScanner2_3.Value,
                        'Batch No': BatchSelection.Selected.Title,
                        ReceiveCheck: ToggleIssue.Value,
                        UserName:MyUser, 
                        ReceivedSatus: "Yet To Receive",
                        When:Today() + Time(Hour(Now()), Minute(Now()),Second(Now()))    
                    },
                    If(PrefixSelected.Selected.Title="1S",
                        {'Product Code': Mid(BarcodeScanner2_3.Value,3,10)},
                        {}
                    )
                )
            })
        )
    )
)

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

Sure @RandyHayes ,

but I can only check it tomorrow and Sorry for taking your time on this silly condition, but I am actually unable to create the logic by using the conditions.

 

and can you please tell me what have you changed in the formula? I mean how it will work according to my logic if you can explain it.

Thanks

@MH3 

Sure, let me know.

 

The change is that before I had the patching in the "else" of the Switch statement.  I had somehow understood that that was the only time a patch would occur.

In the changed formula, the switch happens only for the purpose of checking the two conditions.  Then, there is a separate If to see if either of the conditions in the switch were not met.  If they were "clear"/false, then the check for the record and ultimately (if no record) that patch occurs.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Oh Thanks @RandyHayes ,

 

I will let you know soon.

Many Many Many Many Thanks @RandyHayes ,

 

your code worked like a Charm!!!

 

Now, I have to scan these codes at the receiving screen with same Prefix Selected and it will update the record of that code with the status of "Received", and if it's already received than it will show popup "Already Received".

 

I have used this logic but somehow, it always showing the popup although I have used && in the condition to be both true.

If(ToggleIssue_1.Value=true,

    Switch(RecScanPrefix.Selected.Title,
        // if the user has selected (1S) and if he tries to scan a serial code, or any other code which does not match, it will show a popup, Not a 1S  Code
        "1S", Set(_NotISCode, !(RecScanPrefix.Selected.Title = Left(BarcodeScanner2_4.Value,2))),
        
        // if the user has selected (S) and if he tries to scan a serial code, or any other code which does not match, it will show a popup, Not a S  Code
        "S", Set(_NotSerialCode, !(RecScanPrefix.Selected.Title = Left(BarcodeScanner2_4.Value,1)))
    );

If(!_NotISCode && !_NotSerialCode,

        // Is it already Scanned??
       If(IsEmpty(Filter('Barcodes - Test', BarcodeScanner2_4.Value=Title && ReceivedSatus= "Received")),
            Set(_ReceivePopup, true), // Already Received Popup

        // Else Update Patch,on the scanned code

   UpdateContext({patchedUpdatedRecord:
       Patch('Barcodes - Test',    
       First( Filter('Barcodes - Test', BarcodeScanner2_4.Value=Title, ReceiveCheck="No")),
{ 
  ReceiveCheck: ToggleIssue_1.Value,
   ReceivedSatus: "Received",
   ReceiverName: MyUser,
   ReceivedDate: Today() + Time(Hour(Now()), Minute(Now()),Second(Now()))
  },
  {} 
     )
       })
    )
  )
)

and if there is no Received Status, than Update that record. What am I doing wrong here?

@MH3 

So your logic seems a little off...

You are testing to see if there is a record in the barcodes-test datasource that matches the scanned value and has a status of "received", if there is, then you are displaying a popup.  BUT, then you are saying, if there is NOT a record, then you want to update a record that has receivecheck of "No".  

I am not sure what your actual logic is, but this seems like it is flawed.  

If I had to guess, I would say that your considering that the scanned item comes in and the receivedstatus is set to "Received" and that indicates it is received.  Then you are expecting that someone is going to "check" the received item and once done would flag the record as "ReceiveCheck" - "Yes".

I may be way off on that logic and flow for you, but if that is the workflow, then yes, this formula will not work well.

 

Please clarify.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Hi @RandyHayes 

 

Actually, my Logic is:
I am making an app for a logistic company, the products are going in and out to and from Factory (the Issuing End) to Warehouse (The Receiving End) .

When someone scans at the issuing side, than in the Status Column "Yet To Receive"  and Receive Check to "No" will be stored yesterday we worked on that logic remember?

and now, at the receiving screen, I am using a different bar code control and when the user scans the same code with the same prefix, it will update that code record status to "Received" and Receive Check to "Yes". 


But, at the receiving end if a user scans the same code with the same prefix again, it should not update anything and a popup should be shown as "Already Received".

Hope you understand now?

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (8,241)