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
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (5,464)