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

Order of formulas question

Having some issues with a save button. Have several formulas on the OnSelect. At the moment this runs correctly once. The first patch runs correctly every time, the second patch runs correctly once. First patch sends the input information to a second sharepoint list (Dates), second Patch goes to (Employee Names)

 

Do I even need the SubmitForm with the patches? Should I just patch everything?

This form is updated daily.

 

 

 

 

Patch(Dates, Defaults(Dates),{Name:Value(DataCardValue12.Text),CheckInDate:Value(DataCardValue15_CheckInDate.SelectedDate),Reason:Value(DataCardValue18_ReasonOut.Selected.Value),SickHoursTaken:Value(DataCardValue1_SickHours.Text),VacationHoursTaken:Value(DataCardValue23_VacationHoursTaken.Text)});

SubmitForm(Form2);

Set(currentRecord, LookUp('Employee Names', ID = Value(DataCardValue45.Text)));

Patch('Employee Names',currentRecord,{SickHoursTaken:Value(DataCardValue1_SickHours.Text), SickAvailableNow:currentRecord.SickAvailableNow - Value(DataCardValue1_SickHours.Text)});Patch('Employee Names',currentRecord,{VacationHoursTaken:Value(DataCardValue23_VacationHoursTaken.Text), VacationAvailable:currentRecord.VacationAvailable - Value(DataCardValue23_VacationHoursTaken.Text)});

Notify("Record Saved",NotificationType.Success);

 

 

 

AppExample.jpg

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

Hi @adyboon ,

Short answer  - you should not mix SubmitForm and Patch on the same data source in the same bit of code.

A couple of other things

  • If you are updating all the data with Patch/UpdateIf (see below) you do not need a SubmitForm.
  • A Refresh of the data source is always good to see the current state immediately
  • You do not need Value() around text controls unless you are converting them to numbers.
  • UpdateIf is a good alternative to Patch if you are writing to possible empty fields as a known bug may cause these to be not properly updated.

So try below - note I free-typed it so watch commas/brackets etc.

Patch(
   Dates, 
   Defaults(Dates), 
   {
      Name: DataCardValue12.Text,
      CheckInDate: DataCardValue15_CheckInDate.SelectedDate,
      Reason: DataCardValue18_ReasonOut.Selected.Value,
      SickHoursTaken:Value(DataCardValue1_SickHours.Text),
      VacationHoursTaken:Value(DataCardValue23_VacationHoursTaken.Text)
   }
);
UpdateIf(
   'Employee Names',
   LookUp(
      'Employee Names', 
      ID = Value(DataCardValue45.Text)
   ),
   {
      SickHoursTaken:Value(DataCardValue1_SickHours.Text), 
      SickAvailableNow: 
         'Employee Names'.SickAvailableNow - Value(DataCardValue1_SickHours.Text)),
      VacationHoursTaken:Value(DataCardValue23_VacationHoursTaken.Text), 
      VacationAvailable:
         'Employee Names'.VacationAvailable - Value(DataCardValue23_VacationHoursTaken.Text)
   }
);
Refresh('Employee Names');
Refresh(Dates);
Notify("Record Saved",NotificationType.Success)

 

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.

View solution in original post

1 REPLY 1
Super User III
Super User III

Hi @adyboon ,

Short answer  - you should not mix SubmitForm and Patch on the same data source in the same bit of code.

A couple of other things

  • If you are updating all the data with Patch/UpdateIf (see below) you do not need a SubmitForm.
  • A Refresh of the data source is always good to see the current state immediately
  • You do not need Value() around text controls unless you are converting them to numbers.
  • UpdateIf is a good alternative to Patch if you are writing to possible empty fields as a known bug may cause these to be not properly updated.

So try below - note I free-typed it so watch commas/brackets etc.

Patch(
   Dates, 
   Defaults(Dates), 
   {
      Name: DataCardValue12.Text,
      CheckInDate: DataCardValue15_CheckInDate.SelectedDate,
      Reason: DataCardValue18_ReasonOut.Selected.Value,
      SickHoursTaken:Value(DataCardValue1_SickHours.Text),
      VacationHoursTaken:Value(DataCardValue23_VacationHoursTaken.Text)
   }
);
UpdateIf(
   'Employee Names',
   LookUp(
      'Employee Names', 
      ID = Value(DataCardValue45.Text)
   ),
   {
      SickHoursTaken:Value(DataCardValue1_SickHours.Text), 
      SickAvailableNow: 
         'Employee Names'.SickAvailableNow - Value(DataCardValue1_SickHours.Text)),
      VacationHoursTaken:Value(DataCardValue23_VacationHoursTaken.Text), 
      VacationAvailable:
         'Employee Names'.VacationAvailable - Value(DataCardValue23_VacationHoursTaken.Text)
   }
);
Refresh('Employee Names');
Refresh(Dates);
Notify("Record Saved",NotificationType.Success)

 

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.

View solution in original post

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (93,778)