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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch function using W...
Power Apps
Answered

Patch function using With function

(0) ShareShare
ReportReport
Posted on by 521

Good day,
I am trying to achieve how to use a patch inside With function but currently when patching I do patch 3 lists Main List Notes List Project List  and they share a ProjectID from the main list, is it possible to use With function and get ProjectID when patching to speed up my patching time?
Ta

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    Hi @PowerApps11 ,

    You might share your present code here and a bit more detail on where you are getting this data from. With() is nothing more than a (very) temporary Variable and helps more in Delegation.

  • PowerApps11 Profile Picture
    521 on at

    Hi @WarrenBelz 
    Here is my present code at moment it takes a bit of time when creating or updating the record and wanted to speed up my patching new or updating, currently am using a set to get the id from main list and pass it other lists.

    Set(
     varShowSpinner,
     true
    );
    Set(
     varMainRecord,
     Patch(
     MainProjectList,
     If(
     varMainRecordStatus,
     Defaults(MainProjectList),
     varMainRecord
     ),
     {
     Title: varCustomerRecord.Title,
     'Transaction Date': Now(),
     'Due Date': DatePickerDue.SelectedDate,
     CustomerID: varCustomerRecord.ID,
     'Project Status': Dropdown6.Selected,
     AssignedTo: varCurrentUser.Title,
     Notes: TextNotes.Text
     }
     )
    );
    If(
     !IsBlank(TextNotes.Text),
     Patch(
     'Project Notes',
     Defaults('Project Notes'),
     {
     Title: Now(),
     Comments: Trim(varMainRecord.Notes),
     Project: {
     Value: varMainRecord.Title,
     Id: varMainRecord.ID
     },
     ProjectID: Value(varMainRecord.ID)
     }
     );
     ClearCollect(
     colFilesOne,
     ShowColumns(
     AddColumns(
     Gallery1_6.AllItems,
     "base64",
     With(
     {
     varDemoFromAttachmentControl: JSON(
     Image3_10.Image,
     JSONFormat.IncludeBinaryData
     )
     },
     Mid(
     varDemoFromAttachmentControl,
     Find(
     ",",
     varDemoFromAttachmentControl
     ) + 1,
     Len(varDemoFromAttachmentControl) - Find(
     ",",
     varDemoFromAttachmentControl
     ) - 1
     )
     )
     ),
     "base64",
     "Name"
     )
     );
     AddMultiFiles.Run(
     JSON(
     colFilesOne,
     JSONFormat.IndentFour
     ),
     varMainRecord.ID
     );
     Clear(colFilesOne);
     Set(
     varShowForm,
     false
     );
     Set(
     varShowSpinner,
     false
     )
    );

      

  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    Hi @PowerApps11 ,

    I think I have seen this code before - you are not doing any ForAll() Patches, so there is nothing to really speed up. You also have a substantial volume of "action" going on there, so what do you consider slow ?

  • PowerApps11 Profile Picture
    521 on at

    Hi @WarrenBelz 
    Correct used the code on ForAll, but this time when user adding single records. is the code set up looks good to you? is it possible to use it With function instead Set to grab the variable? 
    when I say slow it takes little time to patch some times. 
    Thank you

  • Verified answer
    WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    Hi @PowerApps11 ,

    If you mean varMainRecord, you are setting that to the result of the Patch - I assume you have used it to capture the possibility of a new record (it simply sets any updated record back to the same value). You cannot use With() here as the Variable is the "outside" element, so there is nothing more to do "with" it.

    I am not sure if this will make it any quicker, but I tend to be more specific on the target record.

    Set(
     varMainRecord,
     Patch(
     MainProjectList,
     If(
     varMainRecordStatus,
     Defaults(MainProjectList),
     {ID: varMainRecord.ID},
     ),
     {
     Title: varCustomerRecord.Title,
     'Transaction Date': Now(),
     'Due Date': DatePickerDue.SelectedDate,
     CustomerID: varCustomerRecord.ID,
     'Project Status': Dropdown6.Selected,
     AssignedTo: varCurrentUser.Title,
     Notes: TextNotes.Text
     }
     )
    );

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard