cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
adyboon 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
WarrenBelz Community Champion
Community Champion

Re: Order of formulas question

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
WarrenBelz Community Champion
Community Champion

Re: Order of formulas question

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
secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Top Solution Authors
Top Kudoed Authors
Users online (8,147)