Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

Can't patch more than two data sources with if function

(0) ShareShare
ReportReport
Posted on by

Hi all, 

 

I can't seem to Patch more than two data sources in a single button on select. Is it becuase of my If function?

 

I've tried writting it a few times in different ways, but each time it only ever patches to my first two data sources. Such as using only one If statement and putting all three true patch values in there, but again, no luck. 

 

 

If(
 Or(
 DocumentTypeSelector.SelectedText.Value = "02 - Assembly / Drawing",
 DocumentTypeSelector.SelectedText.Value = "04 - Part / Drawing"
 ),
 Patch(
 IERMasterDocuments,
 Defaults(IERMasterDocuments),
 {
 PartNumber: GeneratedPN.Text,
 CreatedOn: CreatedOn1.Text,
 CreatedBy: CreatedBy1.Text,
 DocumentType: DocumentTypeSelector.Selected.Result,
 System: SystemTypePrefix.Text,
 Project: ProjectTypeSelector.Selected.Result,
 ProjectUniqueNumber: ProjectUnique2.Text,
 Release: IssueInput.Text,
 'Status (crec2_status)': StatusInput.Text,
 Description: DescriptionInput.Text,
 Notes: NotesInput.Text,
 Barcode: GeneratedPN.Text,
 Location: LocationInput.Text,
 StockLevel: Value(QuantityInput.Text),
 Cost: Value(CostInput.Text),
 VendorCost: Value(VendorCostEachInput.Text)
 }
 );,
 false
);
If(
 Or(
 DocumentTypeSelector.SelectedText.Value = "02 - Assembly / Drawing",
 DocumentTypeSelector.SelectedText.Value = "04 - Part / Drawing"
 ),
 Patch(
 IERStockHistories,
 Defaults(IERStockHistories),
 {
 Title:"New Stock",
 PartNumber:GeneratedPN.Text,
 Quantity:Value(QuantityInput.Text),
 CostEach:Value(CostInput.Text),
 CostTotal:Value(CostInput*QuantityInput.Text),
 EffectiveCost:Value(CostInput*QuantityInput.Text),
 TakenBy:User().FullName,
 Date:Text(Now(),"dd-mmm-yy"),
 Reason:"Restocked"
 }
 );,
 false
);
If(
 Or(
 DocumentTypeSelector.SelectedText.Value = "02 - Assembly / Drawing",
 DocumentTypeSelector.SelectedText.Value = "04 - Part / Drawing"
 ),
 Patch(
 IERPartsVendors,
 Defaults(IERPartsVendors),
 {
 PartNumber: GeneratedPN.Text,
 Vendor: VendorPicker.Selected.Result,
 VendorPN: VendorPNInput.Text,
 VendorDescription: VendorDesInput.Text,
 VendorCost: Value(VendorCostInput.Text),
 VendorQty: Value(VendorQtyInput.Text),
 VendorCostEach: Value(VendorCostEachInput.Text)
 }
 );,
 false
);
If(
 Or(
 DocumentTypeSelector.SelectedText.Value = "02 - Assembly / Drawing",
 DocumentTypeSelector.SelectedText.Value = "04 - Part / Drawing"
 ),
 false,
 Patch(
 IERMasterDocuments,
 Defaults(IERMasterDocuments),
 {
 PartNumber: GeneratedPN.Text,
 CreatedOn: CreatedOn1.Text,
 CreatedBy: CreatedBy1.Text,
 DocumentType: DocumentTypeSelector.Selected.Result,
 System: SystemTypePrefix.Text,
 Project: ProjectTypeSelector.Selected.Result,
 ProjectUniqueNumber: ProjectUnique2.Text,
 Release: IssueInput.Text,
 'Status (crec2_status)': StatusInput.Text,
 Description: DescriptionInput.Text,
 Notes: NotesInput.Text,
 Barcode: GeneratedPN.Text
 }
 );
);

Patch(
 IERMasterHistories,
 Defaults(IERMasterHistories),
 {
 PartNumber:GeneratedPN.Text,
 Change:"Initial Creation",
 ChangeBy:User().FullName,
 ChangeOn:Text(Now(),"dd-mmm-yy")
 }
);
Set(
 varInfoMode,
 "0"
);
Reset(DocumentTypeSelector);
Reset('01_SystemTypeSelector');
Reset('02_SystemTypeSelector');
Reset('05_SystemTypeSelector');
Reset('07_SystemTypeSelector');
Reset('04_SystemTypeSelector');
Reset('10_SystemTypeSelector');
Reset(ProjectTypeSelector);
Reset(DescriptionInput);
Reset(NotesInput);
Reset(CreatedOn1);
Reset(LocationInput);
Reset(QuantityInput);
Reset(CostInput);
Reset(VendorPicker);
Reset(VendorPNInput);
Reset(VendorDesInput);
Reset(VendorCostInput);
Reset(VendorQtyInput);
UpdateContext({Checkbox2Value: false});
Navigate(MainScreen)

 

 

Can some one please point out why I can't get this to work? I've been trying to figure out a solution for two days now!

 

Thanks, 

Luke.  

Categories:
  • iAm_ManCat Profile Picture
    18,201 Most Valuable Professional on at
    Re: Can't patch more than two data sources with if function

    Use the Monitor function in Power Apps, then press the button, look at the log in Monitor to see what the issue is, I suspect the later patches are throwing errors but you're not seeing them.

     

    Additionally I would recommend that you should also be implementing the IfError() function whenever you use patch, as you have no guarantee that the patch worked successfully, but then you are resetting controls and navigating away afterwards. We use IfError to notify the user (or do something else) if there was an error while patching.

     

    Cheers,

    Sancho

  • KeithAtherton Profile Picture
    3,646 Most Valuable Professional on at
    Re: Can't patch more than two data sources with if function

    Hi @LukeAThomas. To confirm, the first two data sources (IERMasterDocuments, IERStockHistories) are patched OK but the rest (IERPartsVendors, IERMasterDocuments, IERMasterHistories) are not?

     

    Are the commands after the Patch calls (control Resets, Navigate, etc) working OK?

     

    One test to try would be to call the Patch statements without If blocks around them to identify if the Patch commands themselves are not working as expected.

  • LukeAThomas Profile Picture
    on at
    Re: Can't patch more than two data sources with if function

    Infact, I removed the If function altogether, and I can still only patch the first two data sources, so I guess the question is more, how do I patch more than two different data sources? 

     

    I've been searching and I can't seem to find the answer anywhere.... 

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,524 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,906 Most Valuable Professional

Leaderboard