I have one query related to Power apps. I am stuck in this process. please suggest to me what will be the code for this process.
I am creating an Appraisal application.
I want to create or update records in a SharePoint list named ‘Appraisal Test’ based on user interactions in a Power Apps gallery. Each record contains information like Label1, Label2, and a radio button choice. Records should be associated with the logged-in user’s email (UserName1 column). On click of a button.
OnSelect button on the Screen where Gallery is present
ForAll(
RenameColumns(
Gallery1.AllItems,
“ID”,
“ID1″
),
Patch(
‘Appraisal Test’,
LookUp(‘Appraisal Test’, ID = ID1),
{
Label1: ThisRecord.Label1,
Label2: ThisRecord.Label2,
RadioButton: { Value: Radio4.Selected.Value },
UserName1: varloggedInUser.Email
}
)
)
On Start of App
Set(varLoggedInUser, User());
With(
{wUserRecord: LookUp(Employees, EmailID = varLoggedInUser.Email)},
Set(varUser, wUserRecord.EmpName);
Set(varRole, wUserRecord.UserRoles.Value)
);
The first time I interacted, the ‘UserName1’ column and the radio button were successfully created with the user’s name and chosen value, respectively. However, when I logged in using a different user account, a new row was not created for that user. Instead, the app updated radio button values for the exiting user.”
I will be very grateful if you give me the formula for the above scenario.
Thanks in advance.
Abhishek YadavPosted Aug 31, 2023, 7:38 AM
Based on the scenario you described, it seems like you want to create or update records in a SharePoint list named 'Appraisal Test' based on user interactions in a Power Apps gallery. Each record should contain information like Label1, Label2, a radio button choice, and should be associated with the logged-in user's email (UserName1 column). When the button is clicked, the following code can be used:
This code uses the ForAll function to iterate through each record in the gallery (Gallery1.AllItems). It then checks if a record with the same ID exists in the 'Appraisal Test' list using the LookUp function. If a record exists, it will use the UpdateIf function to update the existing record with the new values. If a record doesn't exist, it will use the Patch function to create a new record with the specified values.
In the On Start of App section, the code assigns the logged-in user's email to the varLoggedInUser variable, and then uses LookUp function to retrieve the corresponding employee record from the 'Employees' list. The 'EmpName' and 'UserRoles.Value' values are assigned to the varUser and varRole variables, respectively.
Please note that this is just an example code based on the information provided, and you may need to modify it to fit your specific requirements and data structure