Skip to main content
Community site session details

Community site session details

Session Id : LNCuFtLyWLowHGUvUMwIi2
Power Apps - Building Power Apps
Answered

Patch data when "OnSuccess" form property and using different IF statement

Like (0) ShareShare
ReportReport
Posted on 21 Apr 2024 03:56:09 by 6

Hello all! I hope this message finds you well and hoping someone can guide me better please

 

I'm building a power app application for a ticket system. I'm using Patch function on "OnSuccess" property of the form,

I have different custom cards because this ticket system has different categories and under those categories exist different custom cards (because they are very specific fields for each category).

 

Whenever a category is selected I would like to patch the data from the category selected fields that are filled in.

I have this following formula: 

 

 

Patch(
 'QA Ticket System_1',
 LookUp(
 'QA Ticket System_1',
 ID = FormRequest_3.LastSubmit.ID
 ),
 {
 // Existing fields data
 'Brief Description': Concatenate(
 "📝 Additional Details: " & Char(10) & Char(10),
 If(
 marketingAreaValue_3.Selected.Value = "Printing",
 Concatenate(
 printingShippingAddress_lbl_3.Text & Char(10) & printingShippingAddres_input_3.Text,
 Char(10),
 printingNameRecipient_lbl_3.Text & Char(10) & printingNameRecipient_input_3.Text,
 Char(10),
 If(
 printingQuestion_input_3.Selected.Value = "What literature would you like printed?",
 Concatenate(
 "🔗 URL: " & printingQuestionURL_input_3.Text & Char(10),
 "#️⃣ Quantity: " & printingQuestionQty_input_3.Text
 ), ""
 )
 )
 ),
 If(
 marketingAreaValue_3.Selected.Value = "Request Access to Platform",
 Concatenate(
 If(
 !IsBlank(txtInput_costCenter_3.Text),
 costCenterAccess_Label_3.Text & Char(10) & txtInput_costCenter_3.Text,
 If(
 !IsBlank(textInput_SalesOffice_3.Text),
 salesOffice_Label_3.Text & Char(10) & textInput_SalesOffice_3.Text
 ), ""
 )
 )
 ),
 Char(10) & Char(10) & DataCardValue26_3.Text
 )
 }
)

 

 

I'm trying to use IF statement whenever a specific marketingAreaValue_3.Selected.Value is selected
for example marketingAreaValue_3.Selected.Value = "Printing" I would like to patch all fields for Printing

and when marketingAreaValue_3.Selected.Value = "Request Access to Platform" I would like to patch all fields applicable for this category, and so on with another different categories, I have 18 categories for the marketingAreaValue_3 field

 

but the issue is that at the moment of testing and submit a form, is not patching/sending data for "Request Access to Platform"

 

can someone please help me or guide me ?

 

thank you in advance!

  • maddum Profile Picture
    6 on 23 Apr 2024 at 13:23:22
    Re: Patch data when "OnSuccess" form property and using different IF statement

    Hi Kuhlani!
    Thank you for your response,

    That worked really well for me! 😄 

    Thank you so much!

  • Verified answer
    Kuhlani Profile Picture
    82 on 22 Apr 2024 at 00:17:11
    Re: Patch data when "OnSuccess" form property and using different IF statement

    From Power Fx reference:

     


    • If successful, the Form's OnSuccess behavior runs, and the Error and ErrorKind properties are cleared. If the form was in FormMode.New mode, it is returned to FormMode.Edit mode.
    • If unsuccessful, the Form's OnFailure behavior runs, and the Error and ErrorKind properties are set accordingly. The mode of the form is unchanged.

    I'm guessing what if you are either resetting the form and losing the value of the field or if the behavior or switching to FormMode.Edit is done AFTER OnSuccess which means you may not have value in the field to process.

     

    Whatever is the reason, try to use the data from LastSubmit instead of the control itself in the switch statement. Something like:

     

    For text/number fields

     

    FormRequest_e.LastSubmit.YourFieldName

     

     

    For choices field:

     

    FormRequest_e.LastSubmit.YourFieldName.Value

     

     

    instead of the control

     

    marketingAreaValue_3.Selected.Value

     

     

  • maddum Profile Picture
    6 on 21 Apr 2024 at 19:35:22
    Re: Patch data when "OnSuccess" form property and using different IF statement

    Hi Kuhlani, thank you for your response! 
    I did the recommendations you shared with me, but still the data is not being shown on the SharePoint item record, the 'Brief Description' field is showing empty, maybe I'm doing something wrong.

     

    this is the test formula I'm using with the Switch and string interpolation 

     

     

    Patch(
     'QA Ticket System_1',
     LookUp(
     'QA Ticket System_1',
     ID = FormRequest_3.LastSubmit.ID
     ),
     {
     // Existing fields data
     'Brief Description': 
     Switch(
     marketingAreaValue_3.Selected.Value,
     "Printing",
     $"
     Additional Details:
     {printingShippingAddress_lbl_3.Text}
     {printingShippingAddres_input_3.Text}
     {printingNameRecipient_lbl_3.Text}
     {printingNameRecipient_input_3.Text}
     {
     If(
     printingQuestion_input_3.Selected.Value = "What literature would you like printed?",
     $"
     URL: {printingQuestionURL_input_3.Text}
     Quantity: {printingQuestionQty_input_3.Text}
     ",
     ""
     )}
     ",
     "Request Access to Platform",
     $"
     {costCenterAccess_Label_3.Text}
     {txtInput_costCenter_3.Text}
     {
     If(
     PlatformAccessValue_3.Selected.Value = "Sales Sync",
     $"{salesOffice_Label_3.Text}
     {textInput_SalesOffice_3.Text}",
     ""
     )}
     ",
     Char(10) & Char(10) & DataCardValue26_3.Text // This is the 'Brief Description' normal field, if they write something in here I would like to send it/show it always.
     )
     }
    )

     

     
    I also tried with Switch statement as first but the result is only patching data from DataCardValue26_3.Text (last value)
    here is the second formula I'm trying

    Switch(
     marketingAreaValue_3.Selected.Value,
     "Printing",
     Patch(
     'QA Marketing Ticket System_1',
     LookUp(
     'QA Marketing Ticket System_1',
     ID = MarketingFormRequest_3.LastSubmit.ID
     ),
     {
     'Brief Description': 
     $"
     Additional Details:
     {printingShippingAddress_lbl_3.Text}
     {printingShippingAddres_input_3.Text}
     {printingNameRecipient_lbl_3.Text}
     {printingNameRecipient_input_3.Text}
     URL: {printingQuestionURL_input_3.Text}
     Quantity: {printingQuestionQty_input_3.Text}
     "
     }
     ),
     "Request Access to Platform",
     Patch(
     'QA Marketing Ticket System_1',
     LookUp(
     'QA Marketing Ticket System_1',
     ID = MarketingFormRequest_3.LastSubmit.ID
     ),
     {
     'Brief Description': 
     $"
     {costCenterAccess_Label_3.Text}
     {txtInput_costCenter_3.Text}
     {salesOffice_Label_3.Text}
     {textInput_SalesOffice_3.Text}
     "
     }
     ),
     
     DataCardValue26_3.Text // Default value 
     )


    Is this correct? or I'm missing something? please let me know your comments.

    thank you in advance for your support!

  • Kuhlani Profile Picture
    82 on 21 Apr 2024 at 04:46:26
    Re: Patch data when "OnSuccess" form property and using different IF statement

    Assuming you want to skip the part of your formula if the condition of marketingAreaValue_3 is not met. In this case, I would recommend using Switch instead to simplify your formula. Switch function reference (last 3 rows in the table) 

     

    'Brief Description':
    Switch(
     marketingAreaValue_3.Selected.Value,
    
     "Printing",
     forumla/values you'd like to pass for this selection,
    
     "Request Access to Platform",
     forumla/values you'd like to pass for this selection,
    
     // and so on
     ,
     // the last block is optional but you can use it to pass default value of none of the conditions is met
    )

     

    You can also further simplify your formula by replacing Concatenate with string interpolation - example:

    $"
     Additional Details: 
     {printingShippingAddress_lbl_3.Text}
     {printingShippingAddres_input_3.Text}
     {printingNameRecipient_lbl_3.Text}
     {printingNameRecipient_input_3.Text}
    "
    &
    If(printingQuestion_input_3.Selected.Value = "What literature would you like printed?",
     $"
     URL: {printingQuestionURL_input_3.Text}
     Quantity: {printingQuestionQty_input_3.Text}
     ",
     "" // return blank if condition is not met for additional input
    )

     

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1