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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Optimizing Code Perfor...
Power Apps
Answered

Optimizing Code Performance on Save

(0) ShareShare
ReportReport
Posted on by 16

Hi Power Apps Community,

I am a Newbie to this Power apps, i have been trying to build an app for the employees to Create or Update records every Month, and save them into the SharePoint list.

So if an employee comes and updates his value for the 1st time in the month then 15 new records with New YearMonth (Example: 2023-11) Stamp are Created, after that in that month (Example :2023-11) if he wants to update again then new records should not be created but the existing records values should be updated.


The create is working quick very well but update is the issue.  

 

I have this formula on the Save Button,

If(
 IsBlank(
 LookUp(
 'Row Arch Comp',
 Employee = Gallery1.Selected.Employee && YearMonth = Text(
 Now(),
 "yyyy-mm"
 )
 )
 ),
// This is the create part where new records for that Month are Created
 Patch(
 'Row Arch Comp',
 ForAll(
 Gallery2.AllItems,
 {
 CompetencyTitle: CompetencyFullName,
 TrainingTitle: TrainingName,
 Employee: Employee_2.Text,
 CompetencyScore: CmpScore_2.Text,
 'Evaluator Email': EvalEmail_2.Text,
 Evaluator: Eval_2.Text,
 EmployeeEmail: EmpEmail_2.Text,
 EmployeeID: EmpID_2.Text,
 Site: Site_2.Selected.Value,
 JobCode: JBC_2.Selected.Value,
 JobCodeDescription: JBCD_2.SelectedText.Value,
 EmployeeHireDate: EmpHD_2.SelectedDate,
 TrainingValue: TrainingDropDown_2.Selected.Value,
 YearMonth: Text(
 Now(),
 "yyyy-mm"
 ),
 'Employee Marker': If(
 CompetencyFullName = "QUA - FAR-FMR-SMR - Readiness Reviews",
 "Yes",
 ""
 )
 }
 )
 ),

// Here my requirement is that I want to Update the Values in the records if they are already created for the Current Month.
 "I have Put this else condition below .Please have a Look :-)"
);
Notify(
 "Success",
 NotificationType.Success
);
Navigate(Screen1);

 
here i have tried the below in the Else Condition place but doesnot seem to work (i.e. Not updating the values into the SP List)

//This is the Code snippet used in the else Condition Place but this is not doing anything

Patch(
 'Row Arch Comp',
 LookUp(
 'Row Arch Comp',
 Employee = Gallery1.Selected.Employee && CompetencyTitle = Gallery2.Selected.CompetencyFullName && YearMonth = Text(
 Now(),
 "yyyy-mm"
 ),
 ForAll(
 Gallery2.AllItems,
 {
 'Evaluator Email': EvalEmail_2.Text,
 Evaluator: Eval_2.Text,
 EmployeeEmail: EmpEmail_2.Text,
 EmployeeID: EmpID_2.Text,
 Site: Site_2.Selected.Value,
 JobCode: JBC_2.Selected.Value,
 JobCodeDescription: JBCD_2.SelectedText.Value,
 EmployeeHireDate: EmpHD_2.SelectedDate,
 CompetencyScore: CmpScore_2.Text,
 TrainingValue: TrainingDropDown_2.Selected.Value
 }
 )
 )
)

 Any Kind of assistance or help is heartfully appreciated 😊

Please help on this as this is crucial for me to complete by this week. 
Thanks again 😊.

Categories:
  • prlofc3 Profile Picture
    16 on at

    Hello @SpongYe @WarrenBelz  @ANB 
    Can any of you PLEASE help me with this issue here ?

  • Verified answer
    WarrenBelz Profile Picture
    156,720 Most Valuable Professional on at

    Hi @prlofc3 ,

    I assume you are using SharePoint here (this will not work otherwise). Also, it is better to refer to the actual fields in the gallery rather than the controls (I assume they have been saved to the data source), so change these if possible. This should update existing records where the SP record exists and create new ones where not. Also if any of these controls are not in the gallery, remove the _Gal. from the front.

    With(
     {
     _YearMonth:
     Text(
     Now(),
     "yyyy-mm"
     )
     },
     Patch(
     'Row Arch Comp',
     ForAll(
     Gallery2.AllItems As _Gal,
     With(
     {
     _Exist:
     LookUp(
     'Row Arch Comp',
     Employee = _Gal.Employee && 
     YearMonth = _YearMonth
     ),
     _Read:
     If(
     _Gal.CompetencyFullName = "QUA - FAR-FMR-SMR - Readiness Reviews",
     "Yes",
     ""
     )
     },
     {
     ID: _Exist.ID,
     CompetencyTitle: _Gal.CompetencyFullName,
     TrainingTitle: _Gal.TrainingName,
     Employee: _Gal.Employee_2.Text,
     CompetencyScore: _Gal.CmpScore_2.Text,
     'Evaluator Email': _Gal.EvalEmail_2.Text,
     Evaluator: _Gal.Eval_2.Text,
     EmployeeEmail: _Gal.EmpEmail_2.Text,
     EmployeeID: _Gal.EmpID_2.Text,
     Site: _Gal.Site_2.Selected.Value,
     JobCode: _Gal.JBC_2.Selected.Value,
     JobCodeDescription: _Gal.JBCD_2.SelectedText.Value,
     EmployeeHireDate: _Gal.EmpHD_2.SelectedDate,
     TrainingValue: _Gal.TrainingDropDown_2.Selected.Value,
     YearMonth: _YearMonth,
     'Employee Marker': _Read
     }
     )
     )
     )
    );

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

  • prlofc3 Profile Picture
    16 on at

    Hello @WarrenBelz 
    Thank you for your Great Solution for above!!


    However, I have changed the Employee and Evaluator Name columns from text to Person. 
    In the power apps I have created a People Picker Combo Box Using the Office 365 Connector. 

    So The Problem here is if there exist more than one person With same name but Different Emails 
    For Example,
    Mike Jacob (Mike.Jacob@email.com) & Mike Jacob (Mike.Jacob-1@email.com)

    The formula is Failing and Give the Error 
    "Network error when using Patch function: The requested operation is invalid."

    I am really unsure What is the Problem here. 
    I have Tried to replace the .DisplayName with .Mail for the Claims property while Patching but still doesn't look like it's working.

    Please help !! 🙏

    MicrosoftTeams-image.png

    Error:

    prlofc3_0-1704850606872.png

     

    Here is the Formula I used

    With(
     {
     _YearMonth: Text(
     Now(),
     "yyyy-mm"
     )
     },
     Patch(
     'TC-MasterFile',
     ForAll(
     Gallery2.AllItems As _Gal,
     With(
     {
     _Exist: LookUp(
     'TC-MasterFile',
     EmployeeName.DisplayName = Gallery1.Selected.EmployeeName.DisplayName && CompetencyTitle = _Gal.CompetencyFullName && YearMonth = _YearMonth
     )
     },
     {
     ID: _Exist.ID,
     EmployeeName: {
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
     Claims: "i:0#.f|membership|" & EmployeeNameCard.Selected.Mail,
     Department: "",
     DisplayName: EmployeeNameCard.Selected.DisplayName,
     Email: EmployeeNameCard.Selected.Mail,
     JobTitle: "",
     Picture: ""
     },
     EvaluatorName: {
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
     Claims: "i:0#.f|membership|" & EvaluatorNameCard.Selected.Mail,
     Department: "",
     DisplayName: EvaluatorNameCard.Selected.DisplayName,
     Email: EvaluatorNameCard.Selected.Mail,
     JobTitle: "",
     Picture: ""
     },
     CompetencyTitle: _Gal.CompetencyFullName,
     TrainingTitle: _Gal.TrainingName,
     CompetencyScore: _Gal.CompScore.Text,
     'Evaluator Email': EvaluatorEmailCard.Text,
     EmployeeEmail: EmployeeEmailCard.Text,
     EmployeeID: EmployeeIDCard.Text,
     Site: EmployeeSiteCard.Selected.Value,
     JobCode: EmployeeJobCodeCard.Selected.Value,
     JobCodeDescription: EmployeeJobCodeDescCard.SelectedText.Value,
     EmployeeHireDate: EmployeeHireDateCard.SelectedDate,
     TrainingValue: If(
     _Gal.TrainingValue.Selected.Value = "Yes",
     "1",
     "0"
     ),
     YearMonth: _YearMonth
     }
     )
     )
     )
     )



     

  • WarrenBelz Profile Picture
    156,720 Most Valuable Professional on at

    @prlofc3 ,

    What is in Active Directory should not affect anything you are patching into a field in your data source from a Combo Box in your Gallery. Again, I cannot see your data or model, and have to rely on you to put the _Gal. prefix on anything inside the gallery.

    With(
     {
     _YearMonth: 
     Text(
     Now(),
     "yyyy-mm"
     )
     },
     Patch(
     'TC-MasterFile',
     ForAll(
     Gallery2.AllItems As _Gal,
     With(
     {
     _Exist: 
     LookUp(
     'TC-MasterFile',
     EmployeeName.DisplayName = _Gal.EmployeeName.DisplayName && 
     CompetencyTitle = _Gal.CompetencyFullName && 
     YearMonth = _YearMonth
     )
     },
     {
     ID: _Exist.ID,
     EmployeeName: 
     {
     Claims: "i:0#.f|membership|" & Lower(_Gal.EmployeeNameCard.Selected.Mail),
     Department: "",
     DisplayName: _Gal.EmployeeNameCard.Selected.DisplayName,
     Email: _Gal.EmployeeNameCard.Selected.Mail,
     JobTitle: "",
     Picture: ""
     },
     EvaluatorName: 
     {
     Claims: "i:0#.f|membership|" & Lower(_Gal.EvaluatorNameCard.Selected.Mail),
     Department: "",
     DisplayName: EvaluatorNameCard.Selected.DisplayName,
     Email: EvaluatorNameCard.Selected.Mail,
     JobTitle: "",
     Picture: ""
     },
     CompetencyTitle: _Gal.CompetencyFullName,
     TrainingTitle: _Gal.TrainingName,
     CompetencyScore: _Gal.CompScore.Text,
     'Evaluator Email': EvaluatorEmailCard.Text,
     EmployeeEmail: EmployeeEmailCard.Text,
     EmployeeID: EmployeeIDCard.Text,
     Site: EmployeeSiteCard.Selected.Value,
     JobCode: EmployeeJobCodeCard.Selected.Value,
     JobCodeDescription: EmployeeJobCodeDescCard.SelectedText.Value,
     EmployeeHireDate: EmployeeHireDateCard.SelectedDate,
     TrainingValue: 
     If(
     _Gal.TrainingValue.Selected.Value = "Yes",
     "1",
     "0"
     ),
     YearMonth: _YearMonth
     }
     )
     )
     )
    )

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 352 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 323

#3
Mohsin Ali Profile Picture

Mohsin Ali 226

Last 30 days Overall leaderboard