cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TB05
Resolver I
Resolver I

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
Super User
Super User

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
Resolver I
Resolver I

@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
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,181)