web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch Function in Canv...
Power Apps
Unanswered

Patch Function in Canvas app to update 2 tables

(0) ShareShare
ReportReport
Posted on by 90

Hi,

 

i am writing a barcode reader app, which is basically scanning barcodes and then checking the dataverse table: contact for eg.

 

If the barcode is found in the table, then update a field, set it to true.

 

Else, if not found, create a new record with the value of that barcode in another table (which has 1 column: number).

 

Here is the code that i have created on the barcode reader component:

Set(
    varScan,
    First(Self.Barcodes).Value
);
Set(
    varRecord,
    LookUp(
        'Asset Managements',
        'Asset Number' = varScan
    )
);
//checks if the asset number is equal to the variable scanned
/*If(
    IsBlank(varRecord),
    Set(
        varRecord,
        Defaults('Asset Managements')
    )
);
*/
If(
    IsBlank(varRecord.'Asset Number'),
    /*Set(
        varRecord,
        Patch(
            'Asset Managements',
            varRecord,
            {'Marche validée': false}
        )
       
    );
    */

    /*
    IsError(
    Patch(
        'Marcheur Non Reconnus',
        Defaults('Marcheur Non Reconnus'),
        {'Asset Number': varScan}
    );), Notify("Error has occured",NotificationType.Error), Notify("Successful",NotificationType.Success)
    */
    Patch('Not Recogniseds', Defaults('Not Recogniseds'), {number:varScan})
    ,
    Set(
        varRecord,
        Patch(
            'Asset Managements',
            varRecord,
            {'Marche validée': true}
        )
    );
   
);

/*
If(
    IsBlank(varRecord),
    Patch(
        'Marcheur Non Reconnus',
        Defaults('Marcheur Non Reconnus'),
        {'Asset Number': varScan}
    )
);
*/
Navigate(ButtonScreen);
 
 
my issue is that it is not creating the new record in the 'not recognised' table.
 
Please help.
 
Thank you

 

 

Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    hey @AsheshR 

     

    can you try this please:

    // Capture the scanned barcode value.
    Set(varScan, First(Self.Barcodes).Value);
    
    // Attempt to find the scanned barcode in the 'Asset Managements' table.
    Set(varRecord, LookUp('Asset Managements', 'Asset Number' = varScan));
    
    // Determine whether the barcode was found.
    If(
     IsBlank(varRecord),
     // If the barcode is not found, try to create a new record in the 'Not Recogniseds' table.
     If(
     IsError(
     Patch('Not Recogniseds', Defaults('Not Recogniseds'), {number: varScan})
     ),
     Notify("Error occurred while creating a new record.", NotificationType.Error), // Notify if an error occurs
     Notify("A new record was successfully created.", NotificationType.Success) // Notify if successful
     ),
     // If the barcode is found, update the 'Marche validée' field to true.
     Set(
     varRecord,
     If(
     IsError(
     Patch('Asset Managements', varRecord, {'Marche validée': true})
     ),
     Notify("Error occurred while updating the record.", NotificationType.Error), // Notify if an error occurs
     Notify("Record was successfully updated.", NotificationType.Success) // Notify if successful
     )
     )
    );
    
    // Navigate to another screen after operation.
    Navigate(ButtonScreen);
    

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • AsheshR Profile Picture
    90 on at

    Hey,

     

    very grateful for helping me. getting some lines in red code, as follows:

    AsheshR_0-1712147737331.png

     

    and here also:

    AsheshR_1-1712147774662.png

     

     

  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    can you also let us know which error message you see?

  • AsheshR Profile Picture
    90 on at

    before applying your new code, i have done : Clone solution.

     

    is it a mistake that i have done?? 😞

  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    what do you mean by clone solution?

     

  • AsheshR Profile Picture
    90 on at

    AsheshR_0-1712148144286.png

     

     

    AsheshR_1-1712148157751.png

     

  • AsheshR Profile Picture
    90 on at

    in the Solution Explorer, i clicked on the 3 dots and then selected Clone > Clone Solution.

     

    i wanted to make a backup copy before putting your new code ..

  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    should not really make a difference in my opinion

     

     

  • AsheshR Profile Picture
    90 on at

    Thank you. did you have a look at the errors underlined in red? its telling the function IsBlank has some invalid argument type..

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard