cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
lhowlett2022
Frequent Visitor

Changing a choice status via Patch

Hi Powerappers.

 

I a bit stuck on this.  We have an internal approval workflow, with the first approver approving daily, and the second and third apprrovers see all that they need to review to approve / decline once a week.  I went down the path of a deep link with an email notification of daily for one manager or a weekly recurring flow to the other two managers, one on one day and the other the next day.   The item status to the user with each user having a different status assigned.

 

The problem that I am having is the patch function to amend the choice status field.  The managers fields are in the same SP list and are a text single line field.

 

Below is my attempt.  Firstly I am not sure that I have created the formula correctly.  It was working but something is telling me that it's not quite correct and may cause an issue, probably when I hand it off to the bosses 😀.   The first patch is for the first approver that receives the daily approval request to review, so the item based on her user name will show the New Status and on approval changes the Status to First Manager Approved, the next person receives an email and it changes the status for First Manager Approved to Pending and the last Manger receives an email with the link and the status is Pending and changes to Approved to Refund.

 

I also want to include in the patch the user / date information and have this populate the sharepoint list but each time I add this to the formula below,   powerapps becomes unhappy so I am fairly sure that I have an error in the formula below or I am putting the recoding of the approval patch in the completely wrong area.  I've tried patching statement after each approval patch but I have something wrong.  

 

Any assistance would be fantastic, Cheers 

 

 

 

  • Current patch statement for approvers

 

Approval Patch

If(
ThisItem.Status.Value = "New",
Patch(
'Refund Request',
ThisItem,
{Status: {Value: "First Manager Approved"}}
)
);
If(
ThisItem.Status.Value = "First Manger Approved",
Patch(
'Refund Request',
ThisItem,
{Status: {Value: "Pending"}}
)
);
If(
ThisItem.Status.Value = "Pending",
Patch(
'Refund Request',
ThisItem,
{Status: {Value: "Approved to Refund"}}
)
);

 

  • The patch statment to record the user and the date of the approval.

 

Approver:
{
Claims: Concatenate(
"i:0#.f|membership|",
User().Email // Person email
),
Department: "",
DisplayName: User().FullName,
Email: User().Email, // Person email
JobTitle: "",
Picture: ""
}, 'Approval Date': Now(),'Approver History': $"Approval Status Update to <b>First Manager Approved</b> by {User().FullName} at {Now()} </br></br> Request Status: New "})

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @lhowlett2022 ,

Note this is free-typed so watch commas/brackets etc, but try this structure

With(
   {
      wVal:
      Switch(
         ThisItem.Status.Value,
         "New",
         "First Manager Approved",
         "First Manger Approved",
         "Pending",
         "Pending",
         "Approved to Refund"
      )
   },   
   Patch(
      'Refund Request',
      {ID: ThisItem.ID},
      {
         Status: {Value: wVal},
         Approver:
         {
            Claims: "i:0#.f|membership|" & Lower(User().Email),
            Department: "",
            DisplayName: User().FullName,
            Email: User().Email,
            JobTitle: "",
            Picture: ""
         }, 
         'Approval Date': Now(),
         'Approver History': 
         "Approval Status Updated to <b>" & wVal & "</b> by " & User().FullName & 
         "</b> at " & Text(Now(),"dd/mm/yyyy hh:mm am/pm") & " </br></br> Request Status: " & wVal   
      }
   )
)
         

 

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.

Visit my blog Practical Power Apps

View solution in original post

3 REPLIES 3
WarrenBelz
Super User
Super User

Hi @lhowlett2022 ,

Note this is free-typed so watch commas/brackets etc, but try this structure

With(
   {
      wVal:
      Switch(
         ThisItem.Status.Value,
         "New",
         "First Manager Approved",
         "First Manger Approved",
         "Pending",
         "Pending",
         "Approved to Refund"
      )
   },   
   Patch(
      'Refund Request',
      {ID: ThisItem.ID},
      {
         Status: {Value: wVal},
         Approver:
         {
            Claims: "i:0#.f|membership|" & Lower(User().Email),
            Department: "",
            DisplayName: User().FullName,
            Email: User().Email,
            JobTitle: "",
            Picture: ""
         }, 
         'Approval Date': Now(),
         'Approver History': 
         "Approval Status Updated to <b>" & wVal & "</b> by " & User().FullName & 
         "</b> at " & Text(Now(),"dd/mm/yyyy hh:mm am/pm") & " </br></br> Request Status: " & wVal   
      }
   )
)
         

 

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.

Visit my blog Practical Power Apps

Hi @WarrenBelz  thanks so much for taking the time to review my formula.  I'm close, I'm currently getting the approver information back but it is stating the  wVal text instead of user name and time etc.  I will have another go tomorrow, I've run out of steam tonight, thanks again, 

 

Hi @WarrenBelz  Worked like a charm after check my typing skills.  Again, thanks for your help, not only with this ticket but I frequently find the answers that I am looking for from your responses.

 

Merry Christmas to you and your family and a healthy and safe New Year, Cheers

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,550)