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

Patch function is not working?

Hello,

I put the code on "Submit" button, it is not working. no error message, just the "Assigned" value is not replace the NEW. can I ask what's wrong with it? many thanks,

 

If(DataCardValue15.Selected.Value="NEW", Patch(OSART;Defaults(OSART),{Status: LookUp(Choices(OSART.Status),Value="ASSIGNED")}),"")
;SubmitForm(SharePointForm1)

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Linda777 ,

There are several ways of doing this including modifying the control before saving, but I will go with this one - put this on the OnSuccess of the form

If( 
   Self.LastSubmit.Status="NEW", 
   Patch(
      OSART
      {ID:Self.LastSubmit.ID},
      {Status:"ASSIGNED"}
   )
)

 

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

6 REPLIES 6
Super User III
Super User III

HI @Linda777 ,

What exactly are you trying to do here?

If(
   DataCardValue15.Selected.Value="NEW", 
   Patch(
      OSART;
      Defaults(OSART),
      {
         Status: 
         LookUp(
            Choices(OSART.Status),
            Value="ASSIGNED"
         )
      }
   ),
   ""
);
SubmitForm(SharePointForm1)

You are firstly creating an new record in OSART and patching to the Status field (this will not be the same record as your SubmitForm).

If you are simply wanting to patch "ASSIGNED" to the Status column of your record if DataCardValue15 selected value is "NEW", put the Status field on the form with the Default

If( 
   DataCardValue15.Selected.Value="NEW", 
   "ASSIGNED",
   Blank()
)

and simply submit the form.

 

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.

Hello Warren,

Sorry for confusing.
There is a field named "Status" (DataCardValue15), by default, it is "NEW"., once the document is edited, the users click on the "Save" button, The status field need should be changed as "ASSIGNED" automatically. that's the code ( putting on "OnSelect" of the "Save" button) I am trying. 
Thank you very much!

 

 

Hi @Linda777 ,

There are several ways of doing this including modifying the control before saving, but I will go with this one - put this on the OnSuccess of the form

If( 
   Self.LastSubmit.Status="NEW", 
   Patch(
      OSART
      {ID:Self.LastSubmit.ID},
      {Status:"ASSIGNED"}
   )
)

 

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

Hello Warren,

Thank you very much, I got it works followed your tips.

If( Self.LastSubmit.Status.Value="NEW",
Patch('OSART',First(Filter(OSART,ID=Self.LastSubmit.ID )),
{Status:
{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",ID:2 ,Value:"ASSIGNED"}}
) )
;ResetForm(Self); RequestHide()

 

Many thanks!

Hi @Linda777 ,

Just a couple of tips that may help you.
Now I see your Status column is a LookUp, you do need that structure, however you no longer need the @odata.type reference (although it still works) - Microsoft quietly removed the need for this a little while back.

Clearly ASSIGNED is Id 2 in your LookUp list? You might consider doing this as Text in the future and hard-coding the Items of the Power Apps dropdown.

Also Lookup() is the same as First(Filter()), but the {ID:Self.LastSubmit.ID} also works fine and is a bit shorter.

Thanks Warren!! 🙂

Helpful resources

Announcements
secondImage

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Power Apps Community Call

Power Apps Community Call: February

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

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

Top Kudoed Authors
Users online (26,138)