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 

Got that, but where the confusion comes in is within your formula...

In the first check (If) you are seeing if there is a record - based on ReceiveStatus being "Received".  

Then, assuming there is a record based on the above, you are trying to then lookup another record where ReceiveCheck is "No".  Then you are trying to set the status of the ReceiveStatus to "Received".

 

I'm confused....is there one record matching the scanned barcode or many?

_____________________________________________________________________________________
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, I just need to update that record whoever code is being scanned in the receiving screen and thus the status should be updated to "Received" and if the user scans the code again which is already set to status received, than it should show the popup of "Already Received" which is my _receivePopUp, 

can you modify this, I was just trying to think and I created this if condition. 😄 

 

that's the logic I wanna do

@MH3 

Yes, all doable, but the question still remains....is the barcode unique?  Is there one or many records associated with a barcode that is scanned?

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

No No Sir, @RandyHayes 

 

There will be One bar code per record, no multiple records as the product bar code is unique for every product.

It will just update the record of that bar code record to the status "Received" and only that record will be affected,

which ever code is being scanned. and if the user scans again than it should show popup "Already Popup" which is Set(_ReceivePopup,true)

Thanks

@MH3 

Okay...that clears things a little.

So, consider this formula:

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,
        With({theRecord: Lookup('Barcodes - Test', BarcodeScanner2_4.Value=Title)},
        
        //Is this a valid record?
        If(IsBlank(theRecord.ID), 
            Set(_NotValidCode, true),
        
        // Is it already received??
        theRecord.ReceivedSatus= "Received",
            Set(_ReceivePopup, true), // Already Received Popup

        // Else Update Patch,on the scanned code
        Patch('Barcodes - Test', theRecord, 
            { 
             ReceiveCheck: ToggleIssue_1.Value,
             ReceivedSatus: "Received",
             ReceiverName: MyUser,
             ReceivedDate: Today() + Time(Hour(Now()), Minute(Now()),Second(Now()))
            },
        )
    )
)

Note: there is one condition in this that I believe was not accounted for - not a valid scan (i.e. no scan record).

So, look in the formula and see that I followed your logic for popups and have a _NotValidCode variable in there that would be set to true if the scanned code was not found.

 

See if this moves you forward.

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

Hello @RandyHayes 

 

Thanks for everything Sir,

 

But I want to ask will your formula update that scanned code record which already exists? in the DataBase as I have to update only that barcode which is being scanned at the receiving end. 

Please advice.. Thanks

@MH3 

Yes, if there is only one record as you mention, then this is the only record being updated/patched.

It is what is looked up and assigned to the theRecord With variable.  It is then used as the record to update for the 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!

Hi @RandyHayes ,

 

Oh I have never used this kind of variable patching, it's really new for my knowledge.



Thanks

@MH3 

Yes, you're actually not patching a variable.  What is happening is that the With variable is a local scope variable that is assigned the record from the Lookup...it is the same as doing a lookup inline, except you only have to do it once.

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

That's Great @RandyHayes 

 

I haven't used With before, sounds really new to me but it's fine, I have learned something new from you 🙂 

 

Many Many Thanks 🙂 

 

I'll reach out to you when I am stuck 😄🤣

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