cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TB05
Helper II
Helper II

Check if records exist for multi update

Hi, 

I am updating a SP list for multiple users.  This part works, multiple users are updated at once.  But I want to check the SP list for the selected users and date to confirm if record exist and only update those where the record does not exist and display a message stating that the Record for "user" already exist for that "date"! 

 

TB05_0-1631800037324.png

 

Thanks,

TB05

4 REPLIES 4
Nogueira1306
Community Champion
Community Champion

Hey! For Update you need to use:

 

Patch( DataSource, LookUp(DataSource, ID = ThisItem.ID), {...})

 

To create a new one you can use that

So, in your case you need to do this:

 

ForAll(...,

If(IsEmpty(..))

UPDATE,

CREATE NEW

)

 

I am not writting all code but I think you understood

 

If you need additional help please tag me in your reply and please like my reply.
If my reply provided you with a solution, pleased mark it as a solution ✔️!

Best regards,
Gonçalo Nogueira

Check my LinkedIn!

Check my User Group (pt-PT)! 

@Nogueira1306 

Thank you for your quick response.  I'm obviously missing something...as I do have For All...and And IF....but it doesn't work.

ForAll(
Filter(
GallerySelEmp_2.AllItems,
Checkbox2_7.Value
),
If(
IsEmpty(
LookUp(
BonusInput,
Date = DataCardValue12_2.SelectedDate && GallerySelEmp_2.Selected.ID = TimeID
)
),
Patch(
BonusInput,
Defaults(BonusInput),
{
Date: DataCardValue12_2.SelectedDate,
Comments: txtComments.Text,
Title: Employee.DisplayName,
JobID: varJobID.Title,
DailyBonus: Switch(
Dropdown2.Selected.Value,
"Bonus1",
Sum(
Value(JobCode_x003a_DayRate.Value),
Value(JobCode_x003a_MSKBonus.Value),
Value(JobCode_x003a_Tier1.Value)
),
"Bonus2",
Sum(
Value(JobCode_x003a_MSKBonus.Value),
Value(JobCode_x003a_Tier2.Value)
),
"Bonus3",
Sum(
Value(JobCode_x003a_DayRate.Value),
Value(JobCode_x003a_Tier3.Value)
),
"Heliport",
Value(JobCode_x003a_MSKBonus.Value),
"Boat",
Value(JobCode_x003a_DayRate.Value),
"Standby",
Value(JobCode_x003a_DayRate.Value)
),
TimeID: ID,
PayPeriodID: Value(varPayPeriodSelected.ID),
Stat: Checkbox2_4.Value,
StatValue: If(
Checkbox2_4.Value = true,
Value(JobCode_x003a_DayRate.Value)
),
PayPeriodStartDate: varPayPeriodSelected.StartDate,
PayPeriodEndDate: varPayPeriodSelected.EndDate,
Status: {Value: "Pending"},
GIN: Value(Title)
}
)
)
);

TB05
Helper II
Helper II

@Nogueira1306 , I had an issue with parenthesis.  Thanks for your suggestion, it helped me locate my error. 

The first part of my code, will update  multiple records to the  SP list if the record does not exist.  But let's say I select multiple Items to update and only one of them already has a record in the list.  So right now, no records will update.  Is there a way so that only the record that exist does not get added?

Hi @TB05 ,

Firstly, you seem to have an extra closing bracket - If you use Format Text, it will parse it like the below if it is correct. Also, this structure should get you what you need.

ForAll(
   Filter(
      GallerySelEmp_2.AllItems,
      Checkbox2_7.Value
   ),
   Patch(
      BonusInput,
      With(
         {
            wID:
            LookUp(
               BonusInput, 
               Date=DataCardValuel2_2.SelectedDate && 
               ID=TimeID
            ).ID
         },
         If(
            !Blank(wID),
            {ID:wID},
            Defaults(BonusInput),
         },
         {
            Date: DataCardValue12_2.SelectedDate,
            Comments: txtComments.Text,
            Title: Employee.DisplayName,
            JobID: varJobID.Title,
            DailyBonus: 
            Switch(
               Dropdown2.Selected.Value,
               "Bonus1",
               Sum(
                  Value(JobCode_x003a_DayRate.Value),
                  Value(JobCode_x003a_MSKBonus.Value),
                  Value(JobCode_x003a_Tier1.Value)
               ),
               "Bonus2",
               Sum(
                  Value(JobCode_x003a_MSKBonus.Value),
                  Value(JobCode_x003a_Tier2.Value)
               ),
               "Bonus3",
               Sum(
                  Value(JobCode_x003a_DayRate.Value),
                  Value(JobCode_x003a_Tier3.Value)
               ),
               "Heliport",
               Value(JobCode_x003a_MSKBonus.Value),
               "Boat",
               Value(JobCode_x003a_DayRate.Value),
               "Standby",
               Value(JobCode_x003a_DayRate.Value)
            ),
            TimeID: ID,
            PayPeriodID: Value(varPayPeriodSelected.ID),
            Stat: Checkbox2_4.Value,
            StatValue: 
            If(
               Checkbox2_4.Value,
               Value(JobCode_x003a_DayRate.Value)
            ),
            PayPeriodStartDate: varPayPeriodSelected.StartDate,
            PayPeriodEndDate: varPayPeriodSelected.EndDate,
            Status: {Value: "Pending"},
            GIN: Value(Title)
         }
      )
   )
)

 

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.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,605)