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

@MH3 

One comma missing!  Please scrub through the formulas I provide as I type them by hand without the aide of a design editor.

If(!ToggleIssue.Value,

    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
            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!

Dear Sir @RandyHayes ,

 

I have tried to see that but unfortunately, couldn't find that Comma missing issue, but there is still an error, called Record Type required, why you are patching only Product code if it's "1S" Selected?

I actually want to patch all the details as it set for Serial Code "S" and for "1S",  The Difference between them is that, the Product code is in for "1S" and the serial code is trimmed for "1S". differently, I will show you the patch commands:

Patch Columns for "1S"

 Patch('Barcodes - Test',
   
   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()))    
   }


Patch Columns for "S"

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()))    
   }



and in your code you have set only product code as the else for "1S".  Need help in this if condition solution. Sorry for disturbing you on one same topic. but I am kinda confused. 


Thanks

@MH3 

The formula I provided patches for both conditions.

The formula should be (this is just a recopy of the last posting - no changes made):

If(!ToggleIssue.Value,

    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
            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)},
	            {}
	        )
            )
        )
    )
)

 

Where specifically in the formula are you seeing the error?

_____________________________________________________________________________________
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 

The issue is here:
Switch.jpg

But Mr. Randy as I said, there must be two patch statements for "S" and "1S" because the trimming functions are different for both of them, I want to in corporate those two patch commands I sent you earlier in this logic..

 

Hope you understand, that two patch commands will be used one for "S" and another one for "1S"..

@MH3 

Let me review the formula a little closer.  In theory it should be working fine, but I might have overlooked something while hand typing.

As for the two patches...there IS a patch for each type "S" and "1S".  You are not seeing that there is one patch statement, but it has the logic in it to incorporate both into one primary patch. 

_____________________________________________________________________________________
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 Yes @RandyHayes ,
I am sorry, I haven't looked that the serial code, has the same trimming function for both "S" and "1S", My BAD!!

 

but the code isn't working what's wrong in it?

 

@MH3 

I'm looking into that right now...stay tuned!

_____________________________________________________________________________________
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!

@MH3 

I see the issue - it's because the if statement is getting mismatched returns.

Change formula to the following:

If(!ToggleIssue.Value,

    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)},
                        {}
                    )
                })
            )
        )
    )
)
_____________________________________________________________________________________
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!

Sorry @RandyHayes ,

 

Thanks for your time and effort, the formula shows no error, but I can only check it on Monday!

because right now I don't have any bar codes at home to test out the formula.

 

I will notify you on Monday is that okay? 

Many Thanks, if this formula works as per my expectations, Fingers crossed!!! 

@MH3 

Sounds good.  Let me know.  Have a good weekend.

_____________________________________________________________________________________
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!

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,177)