Hi I'm trying to insert variables into a SQL table via a patch function. The button works fine until I try to capture the User().Email and insert it too.
Patch(
'assurance.comments',
Defaults('assurance.comments'), // If varIdea is blank, use default values; otherwise, use varIdea
{
assurance_contractid: TextInput6.Text, // Use the selected value from ComboBox1_2
assurance_comments: 'text metrics input_5'.Text, // Use the value from text input named 'text metrics input_2'
insert_DateTime: Now(), // Use the current date and time
assurance_userid: User().Email
}
);
All,
Thank you again for your efforts on this.
I've managed to find a solution to this.
When a change was made i.e. adding an additional column to the database table the data connection needed to be dropped and re-added again and the patch is working again.
Hope this helps someone else in a similar situation.
I tried you code and thought the lack of errors was promising but I'm still getting the error: record was not found patch error. I'm starting to think this might be a SQL error as the PowerApp code makes sense but just isn't getting executed. I've posted some snippits in the response above from SQL showing I have the column in SQL but there's a potential issue with the column itself. Going to run this by one of the database SME's to see if it's something I've done wrong on the SQL side. Thanks for your answer
Forgive me I've altered your code a bit. I've tried to change the column name in SQL to [assurance_user_id] instead of [assurance_userid] to see if that would have an affect but the same issue occurs. I have changed your code and have set the onvisible to: LoggedInUserName instead of varUserMail
When i try this code out i still get the Network error when using Patch function: the specified record was not found.
Even though there is a record found in the database e.g. 1MC09 at the bottom
and the column is varchar:
Hi @NiiruK ,
What is the datatype of "assurance_userid"?
If it is string then it will be inserted.
If you still face issue try putting value as "Text(User().Email)"
But if you have different datatype then it won't submit.
To know more about error, you can try the following code:
IfError(
Patch(
'assurance.comments',
Defaults('assurance.comments'), // If varIdea is blank, use default values; otherwise, use varIdea
{
assurance_contractid: TextInput6.Text, // Use the selected value from ComboBox1_2
assurance_comments: 'text metrics input_5'.Text, // Use the value from text input named 'text metrics input_2'
insert_DateTime: Now(), // Use the current date and time
assurance_userid: User().Email
}
),
Notify("Error : " &FirstError.Message, NotificationType.Error, 2000),
Notify("Success", NotificationType.Success, 1000)
);
Hope this helps
Hi @NiiruK ! I assume that you've already made sure that the database column accepts the format you are submitting. The issue could be that the 'get the user's email'-operation is performed parallel inline the patch-operation. Try to set a variable OnStart of the app or OnVisible of the screen that already holds that value:
Set(varUserMail; User().Email)
Patch(
'assurance.comments',
Defaults('assurance.comments'), // If varIdea is blank, use default values; otherwise, use varIdea
{
assurance_contractid: TextInput6.Text, // Use the selected value from ComboBox1_2
assurance_comments: 'text metrics input_5'.Text, // Use the value from text input named 'text metrics input_2'
insert_DateTime: Now(), // Use the current date and time
assurance_userid: varUserMail
}
);
------------------------------------------------------------------------------------------------------------------------------
If I have answered your question / helped to solve your problem, please accept as solution and give me a Thumbs up. Thanks! - Remember: you can accept more than one post as a solution.
WarrenBelz
637
Most Valuable Professional
stampcoin
570
Super User 2025 Season 2
Power Apps 1919
473