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 / Patch field only if ch...
Power Apps
Answered

Patch field only if checkbox ticked - need to press button twice for itto work, weird! please help!

(0) ShareShare
ReportReport
Posted on by 67

I am trying to create a patch that looks at the fields in a form and only executes the patch if an associated checkbox is ticked. I have tried a few ways of ordering the commands, this is as close as I seem to be able to get! This logic works if I press the button twice. First press saves it to the Clausecollection, second press patches it to clause table.

Would you show me how it needs to be changed to make everything happen in one press please?

 
If(
CheckboxClauseName.Value = true,
UpdateIf(ClauseCollection,true, {clauseName: TextClauseName.Text}),
Patch(clauses,ClauseCollection));
 
If(
CheckboxClauseBusinessDescription.Value = true,
UpdateIf(ClauseCollection,true,{clauseBusinessDescription: TextClauseBusinessDescription.Text}),
Patch(clauses,ClauseCollection));
 
If(
CheckboxClausePartyType.Value = true,
UpdateIf(ClauseCollection,true,{clausePartyType: ChoiceClausePartyType.Selected.Value}),
Patch(clauses,ClauseCollection));
 
If(
CheckboxClause_theme.Value = true,
UpdateIf(ClauseCollection,true,{clause_theme: LookupClause_Theme.Selected}),
Patch(clauses,ClauseCollection));
Categories:
I have the same question (0)
  • eka24 Profile Picture
    20,925 on at

    What is not clear to me is the true inside this:

    UpdateIf(ClauseCollection,true, {clauseName: TextClauseName.Text})

    Do you intend checking any column?

    If you can give more explanation

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

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

    Hi @LauraMay ,

     

    You should use ";" instead of "," .

     

    You could try this formula:

    If(
    CheckboxClauseName.Value = true,
    UpdateIf(ClauseCollection,true, {clauseName: TextClauseName.Text});
    Patch(clauses,ClauseCollection));

    If(
    CheckboxClauseBusinessDescription.Value = true,
    UpdateIf(ClauseCollection,true,{clauseBusinessDescription: TextClauseBusinessDescription.Text});
    Patch(clauses,ClauseCollection));

    If(
    CheckboxClausePartyType.Value = true,
    UpdateIf(ClauseCollection,true,{clausePartyType: ChoiceClausePartyType.Selected.Value});
    Patch(clauses,ClauseCollection));

    If(
    CheckboxClause_theme.Value = true,
    UpdateIf(ClauseCollection,true,{clause_theme: LookupClause_Theme.Selected});
    Patch(clauses,ClauseCollection));

     

    Best Regards,
    Wearsky
    If my post helps, then please consider Accept it as the solution to help others. Thanks.

  • Laura May Profile Picture
    67 on at

    Hi all,

    I got this to work using the following, basically doing all the UpdateIf first, then pushing the Patch to the end. The first section creates new records based on the ClauseCollection. The second section edits existing records based on whats in the ClauseCollection

     

    If(GroupClauseCollection = true && CopyCLRecord = true, //Copy Multiple Records
    If(CheckboxClauseName.Value = true, UpdateIf(ClauseCollection, true, {clauseName: TextClauseName.Text}));
    If(CheckboxClauseBusinessDescription.Value = true, UpdateIf(ClauseCollection, true, {clauseBusinessDescription: TextClauseBusinessDescription.Text}));
    If(CheckboxClausePartyType.Value = true, UpdateIf( ClauseCollection, true, {clausePartyType: ChoiceClausePartyType.Selected.Value}));
    If(CheckboxClause_theme.Value = true, UpdateIf(ClauseCollection, true, {clause_theme: LookupClause_Theme.Selected}));
     
    ClearCollect(CopyMultipleClausesCollection, DropColumns(ClauseCollection, "crb8f_clauseuid", "crb8f_clauseid", "ClauseUID" ));
    Patch(clauses,CopyMultipleClausesCollection));

    If(GroupClauseCollection = true && EditCLRecord = true, //Edit Multiple Records
    If(CheckboxClauseName.Value = true,UpdateIf(ClauseCollection, true, {clauseName: TextClauseName.Text}));
    If(CheckboxClauseBusinessDescription.Value = true,UpdateIf(ClauseCollection, true, {clauseBusinessDescription: TextClauseBusinessDescription.Text}));
    If(CheckboxClausePartyType.Value = true, UpdateIf(ClauseCollection, true, {clausePartyType: ChoiceClausePartyType.Selected.Value}));
    If(CheckboxClause_theme.Value = true, UpdateIf(ClauseCollection, true, {clause_theme: LookupClause_Theme.Selected}));
    Patch(clauses, ClauseCollection));

     

     

  • Laura May Profile Picture
    67 on at

    Hi @eka24 The presence of  true inside this:

    UpdateIf(ClauseCollection,true, {clauseName: TextClauseName.Text})

     

    In all honesty, I found the syntax on a forum, I wasnt sure of the purpose of true either but it seems to work.

  • Laura May Profile Picture
    67 on at

    I am now trying to create the equivalent functionality in an App embedded in PowerBi

     

    The faster UpdateIf and Patch approach does not work in an App embedded in PowerBI so I have reverted back to ForAll and Patch approach. The below works to Edit existing records

     

     

    ForAll(
    Collection,
    Patch(
    DataSource,
    LookUp(
    DataSource,
    crb8f_datasourceid = Collection[@crb8f_collectionid]),
    {
    DataSourceField1: DropDownLookUpofDataSourceField1.Selected,
    DataSourceField2: DropDownChoiceofDataSourceField2.Selected.Value,
    etc etc etc,
    }
    )
    )

     

     

    However when it comes to copying existing records, the equivalent Patch does not work, I think because of the difference between the patch expecting a Record and I am giving it a Table from the dropdown (something like that, I may have it the wrong way round!)


    ForAll(
    Collection,
    Patch(
    DataSource,
    Defaults(DataSource),

    {
    DataSourceField1: DropDownLookUpofDataSourceField1.Selected,
    DataSourceField2: DropDownChoiceofDataSourceField2.Selected.Value,
    etc etc etc,
    }
    )
    )
    );

     

    I got round this by trying.......

     

    Patch(collection,

    Defaults(sourcetable),

    { SourceField: LookUp(sourcetable, sourcefield in [@Collection].crb8f_CollectionField) }));

     

    If the collection contains 4 records, all with different field content, the Patch will create 4 records, however all 4 records are crreated exactly the same, but the fields are populated based on the first record Power Apps finds in the Collection table (I guess because I am using the Lookup function) This is the best way I can explain, it.

     

    Collection Records

    Record 1: FieldA: 1a FieldB: 1b FieldC: 1c FieldD: Field updated by user in Power Apps

    Record 2: FieldA: 2a FieldB: 2b FieldC: 2c FieldD: Field updated by user in Power Apps

    Record 3: FieldA: 3a FieldB: 3b FieldC: 3c FieldD: Field updated by user in Power Apps

    Record 4: FieldA: 4a FieldB: 4b FieldC: 4c FieldD: Field updated by user in Power Apps

     

    New Records Required

    Record 5: FieldA: 1a FieldB: 1b FieldC: 1c FieldD: Field updated by user in Power Apps

    Record 6: FieldA: 2a FieldB: 2b FieldC: 2c FieldD: Field updated by user in Power Apps

    Record 7: FieldA: 3a FieldB: 3b FieldC: 3c FieldD: Field updated by user in Power Apps

    Record 8: FieldA: 4a FieldB: 4b FieldC: 4c FieldD: Field updated by user in Power Apps

     

    New Records Created

    Record 5: FieldA: 1a FieldB: 1b FieldC: 1c FieldD: User defined field

    Record 6: FieldA: 1a FieldB: 1b FieldC: 1c FieldD: User defined field

    Record 7: FieldA: 1a FieldB: 1b FieldC: 1c FieldD: User defined field

    Record 8: FieldA: 1a FieldB: 1b FieldC: 1c FieldD: User defined field

     

    Do I need to change when I trigger the ForAll loop or something?

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
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#2
11manish Profile Picture

11manish 203 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard