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 Apps
Answered

Patch cording

(0) ShareShare
ReportReport
Posted on by 2
Hi,
I was trying to create an HR system using Power Apps. In order to apply for leaves and approved by the manager a Patch code was entered. I have obtained support from Corpilot. However, there were errors even though I tried multiple times. 
 
Could someone please help to sort this out. The coding is below;
 
Patch('Leave Requests List',Defaults('Leave Requests List'),{Employee:User().Email,'Start Date':StartDatePicker.SelectedDate,'End Date':EndDatePicker.SelectedDate,'Days Requested':DateDiff(StartDatePicker.SelectedDate,EndDatePicker.SelectedDate,TimeUnit.Days)+1,'Status':"Pending"(,Manager:with({mgrEmail:LookUp('Employees List',Email=User().Email,Manager)},{'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",Claims: "i:0#.f|membership|" & mgrEmail,DisplayName: mgrEmail,Email: mgrEmail}
})
 
Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    You have not posted what the error were and I am assuming a few field types here, but try this for a start (please note that is is always advisable to parse the code as below and you will see structure errors more easily)
    With(
       {
          _Manager:
          LookUp(
             'Employees List',
             Email = User().Email,
             Manager
          ),
          _Days:
          DateDiff(
             StartDatePicker.SelectedDate,
             EndDatePicker.SelectedDate,
             TimeUnit.Days
          ) + 1,
          
       },
       Patch(
          'Leave Requests List',
          Defaults('Leave Requests List'),
          {
             Employee: User().Email,
             'Start Date': StartDatePicker.SelectedDate,
             'End Date': EndDatePicker.SelectedDate,
             'Days Requested': _Days,
             'Status': "Pending",
             Manager:
             {
                Claims: "i:0#.f|membership|" & Lower(_Manager.Email),
                DisplayName: _Manager.DisplayName,
                Email: _Manager.Email,
                Department: "",
                JobTitle: "",
                Picture: ""
             }
          }
       )
    )
     
    Please ✅ Does this answer your question 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 answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn  
  • LG-10061841-0 Profile Picture
    2 on at
    Dear WarrenBelz,
    Thank You  so much, Still have errors. if you can please advise. please see below errors,
     
    The expression is intended to create a new leave request record in the 'Leave Requests List' data source when a button is selected. It looks up the current user's manager from the 'Employees List' based on the user's email, calculates the number of days requested for leave (including both start and end dates), and then patches a new record with details such as the employee's email, leave start and end dates, days requested, status set to "Pending," and manager information formatted with claims and display name.
    The errors are:
    1. **'_Manager' is not defined**: The variable '_Manager' is used but never assigned or declared, causing a name recognition error.
    2. **Invalid use of the '.' operator on error values**: This likely results from trying to access properties of '_Manager', which is undefined.
    3. **Invalid arguments to the 'Lower' function**: The argument passed to Lower() is '_Manager.Email', which is invalid because '_Manager' is not defined.
    4. **'Patch' function has invalid arguments**: The 'Employee' field is assigned a Text value (User().Email) but expects a Record type.
    5. **Use of 'Equals' function incorrectly**: The condition in LookUp uses Equals((Email), (User().Email)), but 'Equals' is not a standard Power Fx function; the correct syntax is Email = User().Email.
    6. **Use of StringLiteral and extra parentheses**: StringLiteral() is not a valid function in Power Fx; string values should be enclosed in double quotes directly. Also, there are unnecessary parentheses around variables and values.
    In summary, the expression has issues with undefined variables, incorrect function usage, type mismatches, and syntax errors that prevent it from working as intended.

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard