cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Advocate II
Advocate II

With & Patch

Hi @ALL,

 

I have a formula with a With-Function for better reading. As example:

 

/*------------------------------------------START-WITH----------------------------------------*/
With({_WITH_DayDifferences:
    DateDiff(Medi.Output_varMedi.VAb;
    Medi.Output_varMedi.VBis;Days)+1};

With({_WITH_colDateRangeMedi:
ClearCollect(colDateRangeMedi;
    AddColumns(FirstN(colLoopMaster;_WITH_DayDifferences);
    "Date";
    DateValue(Text(DateAdd(Medi.Output_varMedit.VAb;Index;Days);"[$-de-DE]dd/mm/yyyy"));
    "Column1";Medi.Output_varMedit.Column1;
    "Column2";Medi.Output_varMedit.Column2;
    ....))
};

With({_WITH_PATCH_NEW:
Set(_varMedi;
    Patch(
        dateMedi;Defaults(dateMedi);
        {
            "Column1";Medi.Output_varMedit.Column1;
            "Column2";Medi.Output_varMedit.Column2;
            ...
        })
    )
};
With({_WITH_PATCH_EDIT:
Set(_varMedi;
    UpdateContext({_WithPatchEdit: true});;
    Patch(
        dateMedi;LookUp(dateMedi;ID=_varNeu.ID);
        {
            "Column1";Medi.Output_varMedit.Column1;
            "Column2";Medi.Output_varMedit.Column2;
            ...
        })
    )
};
/*------------------------------------------END-WITH----------------------------------------*/
/*------------------------------------------START-FORMULA-------------------------------------*/
If(_MediNewBool;

//IF1-True------------New?
If(
    (cboxV1 || cboxV2);
    
    //IF2-True------------------New with cbox------------------------------------//
    _WITH_PATCH_NEW;;
    _WITH_colDateRangeMedi;;
    Set(_VisibleBool; false );

    //IF2-False-----------------New without cbox------------------------------------//
    _WITH_PATCH_NEW;;
    ClearCollect(colMediList;dateMedi);;
    Navigate(MediStart;ScreenTransition.None)
);
//IF1-False----------------------EDIT------------------------------------//
If(
    (cboxV1 || cboxV2);
    
    //IF2-True-----------------EDIT with cbox------------------------------------//
    _WITH_PATCH_EDIT;;
    _WITH_colDateRangeMedi;;
    Set(_VisibleBool; false );
  
    //IF2-False----------EDIT without cbox------------------------------------//
    _WITH_PATCH_EDIT;;
    ClearCollect(colMediList;dateMedi);;
    Navigate(MediStart;ScreenTransition.None))
))))))

For better reading I use the "WITH"-Variables in the If-Function. 

I only want to call the function if the "if" condition is fulfilled. But in the defining of the with-function the Patch is running.

 

How can I define the"WITH"-Variables without running in the defining of the variables.

Or is their a better way?

1 REPLY 1
Resolver III
Resolver III

I will circle back to this should you not get an answer but can I just say quickly. Massive respect for your effort and priority in clearly commenting on what is going on 🙂 This is some of the best commenting I have seen.

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Top Solution Authors
Top Kudoed Authors
Users online (61,949)