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 / Handling Multiple Choi...
Power Apps
Unanswered

Handling Multiple Choice and Search Fields in Patch Function

(0) ShareShare
ReportReport
Posted on by 105

In my application, I have a form that allows me to insert new records and modify existing ones connected to my 'ArchivioSpedizioni2023' database. Upon clicking a button, in addition to the function SubmitForm(FormCamion), I want it so that if the form is in new record mode, it creates a new record in a parallel database called 'DB_PrevisioneArrivi'; if it's in edit mode, it should only update certain fields. I have set the OnSelect function as follows:

SubmitForm(FormCamion);;
If(
 FormCamion.Mode = FormMode.New;
 Patch(
 DB_PrevisioneArrivi;
 Defaults(DB_PrevisioneArrivi);
 {
 Data: Last(ArchivioSpedizioni2023).DataOraCarico;
 RiferimentoSDF: "MGC" & Last(ArchivioSpedizioni2023).ID;
 CaricoScarico: Table({Id: 1, Value: "Carico"});
 RicercaPuntoScarico: Table({Id: 1, Value: "MAG. C"});
 DittaAutista: Last(ArchivioSpedizioni2023).Spedizioniere.Value;
 TargaMotrice: Last(ArchivioSpedizioni2023).TargaMotrice;
 TargaRimorchio: Last(ArchivioSpedizioni2023).TargaRimorchio;
 Container: Last(ArchivioSpedizioni2023).SiglaContainer
 }
 );
 Patch(
 DB_PrevisioneArrivi;
 LookUp(
 DB_PrevisioneArrivi;
 Right(DB_PrevisioneArrivi.RiferimentoSDF; Len(DB_PrevisioneArrivi.RiferimentoSDF) - 3) = Right("MGC" & Last(ArchivioSpedizioni2023).ID; Len(DB_PrevisioneArrivi.RiferimentoSDF) - 3)
 );
 {
 Data: Last(ArchivioSpedizioni2023).DataOraCarico;
 DittaAutista: Last(ArchivioSpedizioni2023).Spedizioniere.Value;
 TargaMotrice: Last(ArchivioSpedizioni2023).TargaMotrice;
 TargaRimorchio: Last(ArchivioSpedizioni2023).TargaRimorchio;
 Container: Last(ArchivioSpedizioni2023).SiglaContainer
 }
 )
)

However, I am encountering errors with the columns CaricoScarico (multiple choice type allowing multiple values) and RicercaPuntoScarico (search type allowing multiple values).

 

Could you help me understand where I am going wrong?

Categories:
I have the same question (0)
  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @roby9390 ,

     

    Could you please share more details about your scenario? What data source are you using, SharePoint or Dataverse? For different data sources, the syntax for updating multiple choices columns varies. Besides, what is a search type column? Do you mean LookUp?

     

    Best regards,

  • roby9390 Profile Picture
    105 on at

    Hi @v-jefferni, thank you for responding.

    This is my form screen

    roby9390_0-1712133549016.png

    This form has the property DataSource: ArchivioSpedizioni2023 (SharePoint list).

    The OnSelect property of the save icon is currently set to SubmitForm(FormCamion). 

    For new requirements I need to add to this last OnSelect property, the creation of a new record in another database called DB_PrevisioneArrivi (SharePoint list); to do this I set up this code:

    SubmitForm(FormCamion);;
    If(
     FormCamion.Mode = FormMode.New;
     Patch(
     DB_PrevisioneArrivi;
     Defaults(DB_PrevisioneArrivi);
     {
     Data: Last(ArchivioSpedizioni2023).DataOraCarico;
     RiferimentoSDF: "MGC" & Last(ArchivioSpedizioni2023).ID;
     CaricoScarico: Table({Value: "Carico"});
     RicercaPuntoScarico: Table(
     {
     Id: 3;
     Value: "MAG. C"
     }
     );
     DittaAutista: Last(ArchivioSpedizioni2023).Spedizioniere.Value;
     TargaMotrice: Last(ArchivioSpedizioni2023).TargaMotrice;
     TargaRimorchio: Last(ArchivioSpedizioni2023).TargaRimorchio;
     Container: Last(ArchivioSpedizioni2023).SiglaContainer
     }
     );
     Patch(
     Filter(DB_PrevisioneArrivi; Stato.Value = "Pianificato");
     LookUp(
     Filter(DB_PrevisioneArrivi; Stato.Value = "Pianificato");
     Right(
     RiferimentoSDF;
     Len(RiferimentoSDF) - 3
     ) = Last(ArchivioSpedizioni2023).ID
     );
     {
     Data: Last(ArchivioSpedizioni2023).DataOraCarico;
     DittaAutista: Last(ArchivioSpedizioni2023).Spedizioniere.Value;
     TargaMotrice: Last(ArchivioSpedizioni2023).TargaMotrice;
     TargaRimorchio: Last(ArchivioSpedizioni2023).TargaRimorchio;
     Container: Last(ArchivioSpedizioni2023).SiglaContainer
     }
     )
    )

    I solved yesterday's problems related to the LookUp and Multiple choices fields. Now I am not getting any errors, yet upon clicking the save button, the form adds the new record (or saves the changes) in the "ArchivioSpedizione2023" database but does not create a new record in the "DB_PrevisioneArrivi" database. All this without showing me any error. 

    Any ideas as to why he is behaving this way?

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @roby9390 ,

     

    First, please move the whole if statement to OnSuccess property of the form, so the formula will only fire when the form was submitted with success.

    OnSelect:

    SubmitForm(FormCamion);;

     

    Then in OnSuccess, you have some syntax errors. Please modify it to:

    If(
     FormCamion.Mode = FormMode.New;
     Patch(
     DB_PrevisioneArrivi;
     Defaults(DB_PrevisioneArrivi);
     {
     Data: FormCamion.LastSubmit.DataOraCarico;
     RiferimentoSDF: "MGC" & FormCamion.LastSubmit.ID;
     CaricoScarico: Table({Value: "Carico"});
     RicercaPuntoScarico: Table(
     {
     Id: 3;
     Value: "MAG. C"
     }
     );
     DittaAutista: FormCamion.LastSubmit.Spedizioniere.Value;
     TargaMotrice: FormCamion.LastSubmit.TargaMotrice;
     TargaRimorchio: FormCamion.LastSubmit.TargaRimorchio;
     Container: FormCamion.LastSubmit.SiglaContainer
     }
     );
     Patch(
     DB_PrevisioneArrivi;
     LookUp(
     Filter(DB_PrevisioneArrivi; Stato.Value = "Pianificato");
     Right(
     RiferimentoSDF;
     Len(RiferimentoSDF) - 3
     ) = Last(ArchivioSpedizioni2023).ID
     );
     {
     Data: FormCamion.LastSubmit.DataOraCarico;
     DittaAutista: FormCamion.LastSubmit.Spedizioniere.Value;
     TargaMotrice: FormCamion.LastSubmit.TargaMotrice;
     TargaRimorchio: FormCamion.LastSubmit.TargaRimorchio;
     Container: FormCamion.LastSubmit.SiglaContainer
     }
     )
    )

     

    Best regards,

  • roby9390 Profile Picture
    105 on at

    Hi @v-jefferni and thanks.

    I followed your advice but the problem still persists. I really can't figure out what is wrong also because, again, I get no errors returned.

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @roby9390 ,

     

    Do you mean neither creating new nor updating exists in DB_PrevisioneArrivi doesn't work? 

     

    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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 326 Most Valuable Professional

#2
11manish Profile Picture

11manish 168

#3
sannavajjala87 Profile Picture

sannavajjala87 75 Super User 2026 Season 1

Last 30 days Overall leaderboard