cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Linda777
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
WarrenBelz
Super User
Super User

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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