sharepointoffice365powerapps

In powerapps, I'm getting the same error saying "name isn't valid" but which is incorrect as it has worked everywhere else?


I'm trying to create two buttons that add or remove a numerical value on a sharepoint list via an overall app. The value is chosen through the use of a slider. No matter what i do, it says "Name isn't valid. 'TotalLeave isn't recognized". The issue is, this exact name works everywhere else. Their are no spelling errors, there are no syntax errors, nothing, or atleast nothing I can see. I cannot for the life of me figure this out. If anyone can help, it would be greatly appreciated.

Code for the add button:


If(
    !IsBlank(
Dropdown_Employee_New
.Selected.EmployeeEmail) && 
Slider_Days
.Value > 0,  // Ensure valid selection and positive days

    Patch(
        EmployeeLeaveBalances,
        LookUp(EmployeeLeaveBalances, EmployeeEmail = 
Dropdown_Employee_New
.Selected.EmployeeEmail),
        {
            TotalLeave: TotalLeave + 
Slider_Days
.Value
        }
    );

    Patch(
        LeaveChangeLog,
        Defaults(LeaveChangeLog),
        {
            EmployeeEmail: 
Dropdown_Employee_New
.Selected.EmployeeEmail,
            EmployeeName: 
Dropdown_Employee_New
.Selected.EmployeeName,
            ChangeType: {
                '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                Value: "Add"
            },
            ChangeAmount: 
Slider_Days
.Value,
            Reason: "Manual adjustment via Add Days",
            ChangedBy: User().Email,
            ChangeDate: Now()
        }
    );

    Notify("Days added successfully!", NotificationType.Success),
    Notify("Please select a valid employee and ensure positive days.", NotificationType.Error)
)

Solution

  • Fixed it. The issue was in the look up.

    If(
    !IsBlank(Dropdown_Employee_New.Selected) && Slider_Days.Value > 0,  // Ensure a valid employee and positive days
    
    // Update the TotalLeave in EmployeeLeaveBalances
    Patch(
        EmployeeLeaveBalances,
        LookUp(EmployeeLeaveBalances, EmployeeEmail = Dropdown_Employee_New.Selected.EmployeeEmail),
        {
            TotalLeave: LookUp(EmployeeLeaveBalances, EmployeeEmail = Dropdown_Employee_New.Selected.EmployeeEmail).TotalLeave 
                        - Slider_Days.Value  
        }
    );