1

I have a bar code application in which I am selecting a prefix before that bar code and scanning the according to that code which is being scanned.

I have set up a switch statement but somehow it's not going into the else part/default part.

My code is here:

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_5.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 enter code here
enter code here

    "S", Set(_NotSerialCode, !(PrefixSelected.Selected.Title = Left(BarcodeScanner2_5.Value,1))),

    // Is it a duplicate?
    If(!IsEmpty(Filter('Barcodes - Test',  BarcodeScanner2_5.Value = Title)),
        Set(_DuplicateScan, true), // Duplicate Popup
        
        // ELSE - Patch Command
        UpdateContext({patchedRecord:
            Patch('Barcodes - Test',    
                Defaults('Barcodes - Test'),
                {
                    SerialCode:Right(BarcodeScanner2_5.Value,8),
                    Title:BarcodeScanner2_5.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_5.Value,3,10)},
                    {}
                )
        )
        }        
    )
 )
)

The code is showing the Above two Popups if I scan the wrong codes, but if I scan the correct codes it's not patching the values.

Where I am wrong here?

1 Answer 1

1

This might work for you,

Put your If statement inside a button (e.g. FunctionButton) and then in your Default option from the Switch statement, do a Select(FunctionButton).

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_5.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 enter code here

    "S", Set(_NotSerialCode, !(PrefixSelected.Selected.Title = Left(BarcodeScanner2_5.Value,1))),
    Select(FunctionButton)
)

OnSelect of the FunctionButton

// Is it a duplicate?
    If(!IsEmpty(Filter('Barcodes - Test',  BarcodeScanner2_5.Value = Title)),
        Set(_DuplicateScan, true), // Duplicate Popup
        
        // ELSE - Patch Command
        UpdateContext({patchedRecord:
            Patch('Barcodes - Test',    
                Defaults('Barcodes - Test'),
                {
                    SerialCode:Right(BarcodeScanner2_5.Value,8),
                    Title:BarcodeScanner2_5.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_5.Value,3,10)},
                    {}
                )
        )
        }        
    )
 )
3
  • Hello, Murilo I have to use this if statement for scanning a bar code, do I have to use 2 buttons?
    – Tera Byte
    Commented Oct 23, 2020 at 6:21
  • Hello :) you might have to have 2 buttons, but 1 of them, the FunctionButton is not visible and just used by the switch statement as a "call" Commented Oct 23, 2020 at 6:29
  • Oh cool, I will apply this and check it out.
    – Tera Byte
    Commented Oct 23, 2020 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.