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

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Patch a new record not work on Form OnSuccess attribute

(0) ShareShare
ReportReport
Posted on by 33

Hi all!

 

The OnSuccess attribute of my form should work like this:

If(form mode= new), it should create a new record on another SP List( tbComentario_appDealReview )  

If(form mode= edit), it should update the record created on the submit of the newform, but if I create the record direct on the SP List, that parts works like a charm

 

SP Lists:

  •  tbOportunity_appDealReview,  thats the form DataSource
  • tbComentario_appDealReview,  Fields of the list {  tbOportunity_ID (FK of the tbOportunity_appDealReview ),  Comentario (text)}

This is the part of code that doesn't work:

 

FormMode.New,
 Patch(
 tbComentario_appDealReview,
 Defaults(tbComentario_appDealReview),
 {
 tbOportunity_ID: Self.LastSubmit.OportunityID,//Value(Self.LastSubmit.OportunityID),
 Comentario: "[ INICIO " & Text( Now(), "dd/mm/yyyy hh:mm:ss" ) & "]" & Char(13)
 }
 )

 

 

 and this is the full  OnSuccess attribute code:

 

// Set last record "Criterio" Value
If(
 Self.LastSubmit.ValorTotal >= 10000000,
 Patch(
 tbOportunity_appDealReview,
 Self.LastSubmit,
 {Criterio: "1"}
 ),
 Self.LastSubmit.Margem <= 35,
 Patch(
 tbOportunity_appDealReview,
 Self.LastSubmit,
 {Criterio: "2"}
 ),
 Self.LastSubmit.Margem > 35 && Self.LastSubmit.Margem <= Self.LastSubmit.MargemTarget,
 Patch(
 tbOportunity_appDealReview,
 Self.LastSubmit,
 {Criterio: "3"}
 ),
 Patch(
 tbOportunity_appDealReview,
 Self.LastSubmit,
 {Criterio: "4"}
 )
);


Switch(
 Self.Mode

//Condition NewForm
 ,FormMode.New,
 Patch(
 tbComentario_appDealReview,
 Defaults(tbComentario_appDealReview),
 {
 tbOportunity_ID: Self.LastSubmit.OportunityID,//Value(Self.LastSubmit.OportunityID),
 Comentario: "[ INICIO " & Text( Now(), "dd/mm/yyyy hh:mm:ss" ) & "]" & Char(13)
 }
 )

//Condition EditForm
 ,FormMode.Edit,
 If(
 !IsBlank(txtComentario_frmCad.Text),
 Patch(
 tbComentario_appDealReview,
 LookUp(
 tbComentario_appDealReview,
 tbOportunity_ID = Self.LastSubmit.OportunityID
 ),
 {
 Comentario: $"{txtHistorico_frmCad.Text}{Char(13)}[{Text(Now(),"dd/mm/yyyy hh:mm:ss")}] {glbCurrentUserDisplayName}:{Char(13)}{txtComentario_frmCad.Text}{Char(13)}----"
 }
 )
 )
);

UpdateContext({FormVisible: false});

Notify(
 "Formulario salvo com sucesso!",
 NotificationType.Success
);

 

I have the same question (0)
  • v-jefferni Profile Picture
    on at
    Re: Patch a new record not work on Form OnSuccess attribute

    Hi @RaphaelMelo ,

     

    Could you please share more details about your data sources? Are all these mentioned columns of type Text/Number?

     

    Best regards,

  • RaphaelMelo Profile Picture
    33 on at
    Re: Patch a new record not work on Form OnSuccess attribute

    SP Lists:

    • tbOportunity_appDealReview, 
      • thats the form DataSource (no problem here, I can create and edit any record of the form source)
    • tbComentario_appDealReview, 
      • record to be edited (when I edit some record of tbOportunity_appDealReview) or created (when I insert a new record on tbOportunity_appDealReview ) 
      • Translated column names

     

    Fields{
    Title: (text),
    Comentary:(text),
    tbOportunity_ID: (numeric),
    Modified: (date/time),
    Created: (date/time),
    CreatedBy: (user),
    ModifiedBy: (user),
    } 

    RaphaelMelo_1-1705577652261.png

     

     

  • RaphaelMelo Profile Picture
    33 on at
    Re: Patch a new record not work on Form OnSuccess attribute

    I was testing the switch condition and find that the  formMode.new condition it's not working. looks like doesn't matter if I start the form as "NewForm(Form_frmCad)" or "Editform(Form_frmCad)", after I submit the form the "FormModestate always be "formMode.Edit".

    Switch(
     Self.Mode
    
     ,FormMode.New, //condition NewForm 
     Set(UI_AppMessage,"TEST FormNew CONDITION");
     Patch(
     tbComentario_appDealReview,
     Defaults(tbComentario_appDealReview),
     {
     tbOportunity_ID: Self.LastSubmit.OportunityID,
     Comentario: "[ INICIO " & Text( Now(), "dd/mm/yyyy hh:mm:ss" ) & "]" & Char(13)
     }
     )
     
     
     ,FormMode.Edit, //condition EditForm
     Set(UI_AppMessage,"TEST FormEdit CONDITION");
     If(
     !IsBlank(txtComentario_frmCad.Text),
     Patch(
     tbComentario_appDealReview,
     LookUp(
     tbComentario_appDealReview,
     tbOportunity_ID = Self.LastSubmit.OportunityID
     ),
     {
     Comentario: $"{txtHistorico_frmCad.Text}{Char(13)}[{Text(Now(),"dd/mm/yyyy hh:mm:ss")}] {glbCurrentUserDisplayName}:{Char(13)}{txtComentario_frmCad.Text}{Char(13)}----"
     }
     )
     )
    );

     

  • Verified answer
    v-jefferni Profile Picture
    on at
    Re: Patch a new record not work on Form OnSuccess attribute

    Hi @RaphaelMelo ,

     

    When you submit a New/Edit form, the form mode will always change to Edit. So, you can first save a variable before triggering the submitform function, and use this variable in If or Switch:

    Set(varMode, Form.Mode = FormMode.New);SubmitForm(YourForm)
    If(
     varMode,
    //Condition NewForm
     Patch(
     tbComentario_appDealReview,
     Defaults(tbComentario_appDealReview),
     {
     tbOportunity_ID: Self.LastSubmit.OportunityID,//Value(Self.LastSubmit.OportunityID),
     Comentario: "[ INICIO " & Text( Now(), "dd/mm/yyyy hh:mm:ss" ) & "]" & Char(13)
     }
     ),
    //Condition EditForm
     If(
     !IsBlank(txtComentario_frmCad.Text),
     Patch(
     tbComentario_appDealReview,
     LookUp(
     tbComentario_appDealReview,
     tbOportunity_ID = Self.LastSubmit.OportunityID
     ),
     {
     Comentario: $"{txtHistorico_frmCad.Text}{Char(13)}[{Text(Now(),"dd/mm/yyyy hh:mm:ss")}] {glbCurrentUserDisplayName}:{Char(13)}{txtComentario_frmCad.Text}{Char(13)}----"
     }
     )
     )
    );
    
    UpdateContext({FormVisible: false});
    
    Notify(
     "Formulario salvo com sucesso!",
     NotificationType.Success
    );

     

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 671 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 424 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 243

Last 30 days Overall leaderboard