web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Use patch with a recor...
Power Apps
Answered

Use patch with a record variable

(0) ShareShare
ReportReport
Posted on by 4

Hi,

I'm looking to create a new record in my sharepointlist, but the record I want to write depends on some previous chosen values.

 

This is my code:

Set(varKoppel;Patch({informatie: txtReden.Text};varKoppel2;varKoppel1));;

Patch(paKoppelingen;Defaults(paKoppelingen);varKoppel)

 

varKoppel1 and varKoppel2 are 2 variables filled with a record (1 column and 1 value)

When I change varKoppel to {PersID: varPers; PlaatsID: varPlaats; informatie: txtReden.text}, it works.

 

Any idea?

varKoppel.jpg
Categories:
  • mdevaney Profile Picture
    29,993 Moderator on at

    @KoenBraem 
    Does varKoppel include the 'ID' field? I don't think this is allowed.  ID is a protected field.

     

    You can define specific fields to patch like this!

    Set(varKoppel;Patch({informatie: txtReden.Text};varKoppel2;varKoppel1));;
    Patch(paKoppelingen;
     Defaults(paKoppelingen);
     {PersID: varKoppel.PersonField; PlaatsID: varKoppel.Plaats; informatie: varKoppel.informatie}
    )
    

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."  

  • KoenBraem Profile Picture
    4 on at

    Thank you for your response, but the problem is that there are about 15 columns in the list.
    I just need to fill in 3 columns, but the first 2 columns depends on previously maden choices.

  • v-yutliu-msft Profile Picture
    Microsoft Employee on at

    Hi @KoenBraem ,

    Do you want to create a new record by using variables?

    Firstly, please notice the syntax of Patch function:

    Patch(data source,Defaults(data source),item)

    Obviously, Patch({informatie: txtReden.Text};varKoppel2;varKoppel1) this function does not meet the requirement.

    The field that you want to update should be specific. It can not be a variable.

    Please describe more clearly about how do you set varKoppel1 and varKoppel2.

     

    If your field need is dynamic, you could use If statement to justify.

    For example:

    If(....;//condition1
    Patch(paKoppelingen;
     Defaults(paKoppelingen);
     {PersID: varPers; PlaatsID: varPlaats; informatie: txtReden.text}
    //{fieldname:value}
     ),
    ....;//condition2
    Patch(paKoppelingen;
     Defaults(paKoppelingen);
     {informatie: txtReden.text,field2:....}
    )
    )
    //if condition2, you will update field2 and informatie field
    

     

     

    I suggest you know more about this function:

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch

     

     

    Best regards,

  • KoenBraem Profile Picture
    4 on at

    The purpose is to connect 2 items (ID's in a different SPlist) and a reason.
    The 2 items can be a person, a place or a vehicle (and later an investigation, a workfile or an action).
    But any connection has to be possible (person-place or person-vehicle of vehicle-investigation or ...)

     

    Switch(Bron;
     "Persoon";Set(varKoppel1; {PersID: SelectedPersID2});
     "Plaats";Set(varKoppel1; {PlaatsID: SelectedPlaatsId});
     "Voertuig";Set(varKoppel1; {VtgID: SelectedVtgId})
    );;
    If(visPersonen;Set(varKoppel2;{PersID2: lstPersonen_1.Selected.'Id (ID)'});
     If(visPlaatsen;Set(varKoppel2;{PlaatsID: lstPlaatsen_1.Selected.'Id (ID)'});
     If(visVoertuigen;Set(varKoppel2;{VtgID: lstVoertuigen_1.Selected.'Id (ID)'}))
     )
    );;
    Set(varKoppel;Patch({informatie: txtReden.Text};varKoppel2;varKoppel1));;
    
    Patch(paKoppelingen;Defaults(paKoppelingen);varKoppel)

     

  • Verified answer
    v-yutliu-msft Profile Picture
    Microsoft Employee on at

    Hi @KoenBraem ,

    Please notice the syntax of Patch function.

    PatchDataSourceBaseRecordsTableChangeRecordTable1 [, ChangeRecordTable2, … ] )

    The last parameter should be the specific record. It can not be variable.

    I suggest you use if statement in your issue.

    For example:

    If(
    Bron= "Persoon"&&visPersonen;
    Patch(paKoppelingen;Defaults(paKoppelingen);{PersID: SelectedPersID2;PersID2: lstPersonen_1.Selected.'Id (ID)';informatie: txtReden.Text});
    Bron= "Plaats"&&visPlaatsen;
    Patch(paKoppelingen;Defaults(paKoppelingen);{PlaatsID: SelectedPlaatsId;PlaatsID: lstPlaatsen_1.Selected.'Id (ID)';informatie: txtReden.Text});
    .....
    )
    

     

     

    Best regards,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 402 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

Last 30 days Overall leaderboard